ash_phoenix/test/support/resources/post.ex
Zach Daniel 9350101bb5 improvement: add use_data? opt to add_related
test: add some tests for `add_related`
fix: don't assume an empty map is an indexed map
2021-07-12 17:19:06 -04:00

35 lines
857 B
Elixir

defmodule AshPhoenix.Test.Post do
use Ash.Resource, data_layer: Ash.DataLayer.Ets
ets do
private?(true)
end
attributes do
uuid_primary_key(:id)
attribute(:text, :string)
end
actions do
create :create do
argument(:comments, {:array, :map})
change(manage_relationship(:comments, type: :replace))
end
update :update do
argument(:comments, {:array, :map})
change(manage_relationship(:comments, type: :replace))
end
end
relationships do
has_many(:comments, AshPhoenix.Test.Comment)
has_one(:featured_comment, AshPhoenix.Test.Comment, read_action: :featured)
many_to_many(:linked_posts, AshPhoenix.Test.Post,
through: AshPhoenix.Test.PostLink,
destination_field_on_join_table: :destination_post_id,
source_field_on_join_table: :source_post_id
)
end
end