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

NameTypeDefaultDocs
primary_key_typeatom:uuidSet the type of the column :id.
attributes_as_attributeslist(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:snapshotChanges are stored in a map attribute called changes. The change_tracking_mode determines what's stored. See the getting started guide for more.
ignore_attributeslist(atom)[]A list of attributes that should be ignored. Typically you'll want to ignore your timestamps. The primary key is always ignored.
ignore_actionslist(atom)[]A list of actions that should not produce new versions. By default, no actions are ignored.
mixinatom | mfaA module that defines a using macro or {module, function, arguments} tuple that will be mixed into the version resource.
on_actionslist(atom)Which actions should produce new versions. By default, all create/update actions will produce new versions.
reference_source?booleantrueWhether 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_optskeywordOptions 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?booleanfalseWhether 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?booleanfalseWhether or not to add the version_resource_identifier attribute to the version resource. This is useful for auditing purposes.
resource_identifieratomA name to use for this resource in the version_resource_identifier. Defaults to Ash.Resource.Info.short_name/1.
version_extensionskeyword[]Extensions that should be used by the version resource. For example: extensions: [AshGraphql.Resource], notifier: [Ash.Notifiers.PubSub]
table_nameString.tThe 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

NameTypeDefaultDocs
nameatomThe name of the relationship to use for the actor (e.g. :user)
destinationmoduleThe resource of the actor (e.g. MyApp.Users.User)

Options

NameTypeDefaultDocs
allow_nil?booleantrueWhether 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.
domainatomThe Domain module to use when working with the related entity.
attribute_typeany:uuidThe type of the generated created attribute. See Ash.Type for more.
public?booleanfalseWhether this relationship should be included in public interfaces
define_attribute?booleantrueIf 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