Automatically sets archive_related
from ash_archival
for all has_many
, has_one
, and many_to_many
relationships.
Add ash_cascade_archival
to your list of dependencies in mix.exs
:
def deps do
[
{:ash_cascade_archival, "~> 0.1.0"}
]
end
defmodule Post do
use Ash.Resource,
data_layer: Ash.DataLayer.Postgres,
extensions: [AshCascadeArchival]
attributes do
uuid_primary_key :id
attribute :title, :string
end
relationships do
belongs_to :author, Author
has_many :comments, Comment
has_many :post_tags, PostTag
many_to_many :tags, Tag, through: PostTag
end
actions do
defaults [:read, :destroy, create: :*, update: :*]
end
end
For the example above, archive_related
of ash_archival
is automatically set as follows.
archive do
archive_related [:comments, :post_tags]
end
MIT