AshReferentialActions (ash_referential_actions v0.1.0)

Copy Markdown View Source

Declares referential actions for Ash relationships.

Persistent relationships must state what happens when the referenced record is destroyed:

  • cascade_* destroys related records through their primary destroy action.
  • restrict_* rejects the destroy while live related records exist.
  • nilify_* clears the foreign key on live related records.
  • do_nothing_* declares a normal Ash relationship without adding lifecycle behavior.

The action is declared on both sides of an attributable relationship:

relationships do
  cascade_belongs_to :post, Post, allow_nil?: false
end

relationships do
  cascade_has_many :comments, Comment
end

Use AshReferentialActions.Archival to apply these semantics to soft archive, or AshReferentialActions.Postgres to apply them to physical PostgreSQL deletes.