2021-07-13 08:29:55 +12:00
|
|
|
defmodule AshPhoenix.Test.Post do
|
2021-07-13 09:19:17 +12:00
|
|
|
@moduledoc false
|
2021-07-13 08:29:55 +12:00
|
|
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
|
|
|
|
|
|
|
ets do
|
|
|
|
private?(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id)
|
2021-07-16 06:09:15 +12:00
|
|
|
attribute(:text, :string, allow_nil?: false)
|
2021-11-30 15:40:46 +13:00
|
|
|
attribute(:title, :string)
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
create :create do
|
|
|
|
argument(:comments, {:array, :map})
|
2021-07-16 06:09:15 +12:00
|
|
|
argument(:linked_posts, {:array, :map})
|
|
|
|
change(manage_relationship(:comments, type: :direct_control))
|
|
|
|
change(manage_relationship(:linked_posts, type: :direct_control))
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
|
|
|
|
2022-03-22 15:24:19 +13:00
|
|
|
update :update_with_replace do
|
|
|
|
argument(:comments, {:array, :map})
|
|
|
|
change(manage_relationship(:comments, type: :replace))
|
|
|
|
end
|
|
|
|
|
2021-07-13 08:29:55 +12:00
|
|
|
update :update do
|
2022-03-22 15:24:19 +13:00
|
|
|
primary?(true)
|
2021-07-13 08:29:55 +12:00
|
|
|
argument(:comments, {:array, :map})
|
2021-07-16 06:09:15 +12:00
|
|
|
change(manage_relationship(:comments, type: :direct_control))
|
2021-07-13 08:29:55 +12:00
|
|
|
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
|