View Source DSL: AshPaperTrail.Resource
Documentation for AshPaperTrail.Resource
.
paper_trail
A section for configuring how versioning is derived for the resource.
Nested DSLs
Options
Name | Type | Default | Docs |
---|---|---|---|
primary_key_type | atom | :uuid | Set the type of the column :id . |
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 | :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 | list(atom) | [] | A list of attributes that should be ignored. Typically you'll want to ignore your timestamps. The primary key is always ignored. |
sensitive_attributes | :display | :ignore | :redact | :display | Controls the behaviour when sensitive attributes are being versioned. By default their values are versioned, but they can be redacted so that you know they changed without knowing the values. |
ignore_actions | list(atom) | [] | A list of actions that should not produce new versions. By default, no actions are ignored. |
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 | list(atom) | Which actions should produce new versions. By default, all create/update actions will produce new versions. | |
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 | 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 Ash.Resource.Dsl.relationships.has_many . | |
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_action_inputs? | boolean | false | Whether or not to add the version_action_inputs attribute to the version resource, which will store all attributes and arguments for the called action, redacting any sensitive values. This is useful for auditing purposes. The version_action_inputs attribute is always stored. |
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 | atom | A name to use for this resource in the version_resource_identifier . Defaults to Ash.Resource.Info.short_name/1 . | |
version_extensions | keyword | [] | Extensions that should be used by the version resource. For example: extensions: [AshGraphql.Resource], notifier: [Ash.Notifiers.PubSub] |
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
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 | atom | The name of the relationship to use for the actor (e.g. :user) | |
destination | module | The resource of the actor (e.g. MyApp.Users.User) |
Options
Name | Type | Default | Docs |
---|---|---|---|
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 | atom | The Domain module to use when working with the related entity. | |
attribute_type | any | :uuid | The type of the generated created attribute. See Ash.Type for more. |
public? | boolean | false | Whether this relationship should be included in public interfaces |
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. |