2021-07-13 08:29:55 +12:00
|
|
|
defmodule AshPhoenix.Test.Comment 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
|
|
|
|
|
|
|
|
actions do
|
|
|
|
read(:read, primary?: true)
|
|
|
|
|
|
|
|
read :featured do
|
|
|
|
filter(expr(featured == true))
|
|
|
|
end
|
|
|
|
|
|
|
|
create :create do
|
2022-05-17 07:34:33 +12:00
|
|
|
primary?(true)
|
2021-07-13 08:29:55 +12:00
|
|
|
argument(:post, :map)
|
2021-07-16 06:09:15 +12:00
|
|
|
change(manage_relationship(:post, type: :direct_control))
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
update :update do
|
2022-05-17 07:34:33 +12:00
|
|
|
primary?(true)
|
2021-07-13 08:29:55 +12:00
|
|
|
argument(:post, :map)
|
2021-07-16 06:09:15 +12:00
|
|
|
change(manage_relationship(:post, type: :direct_control))
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
2022-05-17 07:34:33 +12:00
|
|
|
|
|
|
|
defaults([:destroy])
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id)
|
|
|
|
attribute(:featured, :boolean, default: false)
|
2021-07-16 06:09:15 +12:00
|
|
|
attribute(:text, :string, allow_nil?: false)
|
2021-07-13 08:29:55 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
|
|
|
belongs_to(:post, AshPhoenix.Test.Post)
|
|
|
|
end
|
|
|
|
end
|