ash_postgres/test/support/resources/comment.ex

41 lines
896 B
Elixir
Raw Normal View History

defmodule AshPostgres.Test.Comment do
@moduledoc false
use Ash.Resource,
data_layer: AshPostgres.DataLayer
postgres do
table "comments"
repo AshPostgres.TestRepo
references do
reference(:post, on_delete: :delete, on_update: :update, name: "special_name_fkey")
end
end
actions do
2021-01-13 14:22:28 +13:00
read(:read)
2021-02-01 10:39:59 +13:00
create :create do
argument(:rating, :map)
2021-02-01 10:39:59 +13:00
2021-02-23 17:53:18 +13:00
change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create))
2021-02-01 10:39:59 +13:00
end
end
attributes do
2021-01-13 14:22:28 +13:00
uuid_primary_key(:id)
attribute(:title, :string)
2021-04-05 08:05:41 +12:00
attribute(:likes, :integer)
end
relationships do
2021-01-13 14:22:28 +13:00
belongs_to(:post, AshPostgres.Test.Post)
belongs_to(:author, AshPostgres.Test.Author)
has_many(:ratings, AshPostgres.Test.Rating,
destination_field: :resource_id,
2021-05-14 17:20:10 +12:00
relationship_context: %{data_layer: %{table: "comment_ratings"}}
)
end
end