documentation/dsls/DSL:-AshPaperTrail.Resource.md

<!--
This file was generated by Spark. Do not edit it by hand.
-->
# DSL: AshPaperTrail.Resource

Documentation for `AshPaperTrail.Resource`.


## paper_trail
A section for configuring how versioning is derived for the resource.


### Nested DSLs
 * [belongs_to_actor](#paper_trail-belongs_to_actor)





### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`primary_key_type`](#paper_trail-primary_key_type){: #paper_trail-primary_key_type } | `atom` | `:uuid` | Set the type of the column `:id`. |
| [`attributes_as_attributes`](#paper_trail-attributes_as_attributes){: #paper_trail-attributes_as_attributes } | `list(atom)` | `[]` | A set of attributes that should be set as attributes on the version resource, instead of stored in the freeform `changes` map attribute. |
| [`change_tracking_mode`](#paper_trail-change_tracking_mode){: #paper_trail-change_tracking_mode } | `:snapshot \| :changes_only \| :full_diff` | `:snapshot` | Changes are stored in a map attribute called `changes`.  The `change_tracking_mode` determines what's stored. See the getting started guide for more. |
| [`ignore_attributes`](#paper_trail-ignore_attributes){: #paper_trail-ignore_attributes } | `list(atom)` | `[]` | A list of attributes that should be ignored. Typically you'll want to ignore your timestamps. The primary key is always ignored. |
| [`ignore_actions`](#paper_trail-ignore_actions){: #paper_trail-ignore_actions } | `list(atom)` | `[]` | A list of actions that should not produce new versions. By default, no actions are ignored. |
| [`mixin`](#paper_trail-mixin){: #paper_trail-mixin } | `atom \| mfa` |  | A module that defines a `using` macro or {module, function, arguments} tuple that will be mixed into the version resource. |
| [`on_actions`](#paper_trail-on_actions){: #paper_trail-on_actions } | `list(atom)` |  | Which actions should produce new versions. By default, all create/update actions will produce new versions. |
| [`reference_source?`](#paper_trail-reference_source?){: #paper_trail-reference_source? } | `boolean` | `true` | Whether or not to create a foreign key reference from the version to the source.  This should be set to `false` if you are allowing actual deletion of data. Only relevant for resources using the AshPostgres data layer. |
| [`relationship_opts`](#paper_trail-relationship_opts){: #paper_trail-relationship_opts } | `keyword` |  | Options to pass to the has_many :paper_trail_versions relationship that is created on this resource. For example, `public?: true` to expose the relationship over graphql. See `d:Ash.Resource.Dsl.relationships.has_many`. |
| [`store_action_name?`](#paper_trail-store_action_name?){: #paper_trail-store_action_name? } | `boolean` | `false` | Whether or not to add the `version_action_name` attribute to the  version resource. This is useful for auditing purposes. The `version_action_type` attribute is always stored. |
| [`store_resource_identifier?`](#paper_trail-store_resource_identifier?){: #paper_trail-store_resource_identifier? } | `boolean` | `false` | Whether or not to add the `version_resource_identifier` attribute to the version resource. This is useful for auditing purposes. |
| [`resource_identifier`](#paper_trail-resource_identifier){: #paper_trail-resource_identifier } | `atom` |  | A name to use for this resource in the `version_resource_identifier`. Defaults to `Ash.Resource.Info.short_name/1`. |
| [`version_extensions`](#paper_trail-version_extensions){: #paper_trail-version_extensions } | `keyword` | `[]` | Extensions that should be used by the version resource. For example: `extensions: [AshGraphql.Resource], notifier: [Ash.Notifiers.PubSub]` |
| [`table_name`](#paper_trail-table_name){: #paper_trail-table_name } | `String.t` |  | The table to use to store versions if using a SQL-based data layer, derived if not set |



## paper_trail.belongs_to_actor
```elixir
belongs_to_actor name, destination
```


Creates a belongs_to relationship for the actor resource. When creating a new version, if the actor on the action is set and
matches the resource type, the version will be related to the actor. If your actors are polymorphic or varying types, declare a
belongs_to_actor for each type.

A reference is also created with `on_delete: :nilify` and `on_update: :update`

If you need more complex relationships, set `define_attribute? false` and add the relationship via a mixin.

If your actor is not a resource, add a mixin and with a change for all creates that sets the actor's to one your attributes.
The actor on the version changeset is set.




### Examples
```
belongs_to_actor :user, MyApp.Users.User, domain: MyApp.Users
```



### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`name`](#paper_trail-belongs_to_actor-name){: #paper_trail-belongs_to_actor-name .spark-required} | `atom` |  | The name of the relationship to use for the actor (e.g. :user) |
| [`destination`](#paper_trail-belongs_to_actor-destination){: #paper_trail-belongs_to_actor-destination } | `module` |  | The resource of the actor (e.g. MyApp.Users.User) |
### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`allow_nil?`](#paper_trail-belongs_to_actor-allow_nil?){: #paper_trail-belongs_to_actor-allow_nil? } | `boolean` | `true` | Whether this relationship must always be present, e.g: must be included on creation, and never removed (it may be modified). The generated attribute will not allow nil values. |
| [`domain`](#paper_trail-belongs_to_actor-domain){: #paper_trail-belongs_to_actor-domain } | `atom` |  | The Domain module to use when working with the related entity. |
| [`attribute_type`](#paper_trail-belongs_to_actor-attribute_type){: #paper_trail-belongs_to_actor-attribute_type } | `any` | `:uuid` | The type of the generated created attribute. See `Ash.Type` for more. |
| [`public?`](#paper_trail-belongs_to_actor-public?){: #paper_trail-belongs_to_actor-public? } | `boolean` | `false` | Whether this relationship should be included in public interfaces |
| [`define_attribute?`](#paper_trail-belongs_to_actor-define_attribute?){: #paper_trail-belongs_to_actor-define_attribute? } | `boolean` | `true` | If set to `false` an attribute is not created on the resource for this relationship, and one must be manually added in `attributes`, invalidating many other options. |





### Introspection

Target: `AshPaperTrail.Resource.BelongsToActor`





<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>