ash_postgres/test/support/resources/comment.ex

35 lines
714 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
end
actions do
2021-01-13 14:22:28 +13:00
read(:read)
2021-02-01 10:39:59 +13:00
create :create do
reject [:ratings] # Disallow editing of the relationship itself
manage_related :ratings, :append # Now `ratings` can be used as an argument
end
end
attributes do
2021-01-13 14:22:28 +13:00
uuid_primary_key(:id)
attribute(:title, :string)
end
relationships do
2021-01-13 14:22:28 +13:00
belongs_to(:post, AshPostgres.Test.Post)
has_many(:ratings, AshPostgres.Test.Rating,
destination_field: :resource_id,
context: %{data_layer: %{table: "comment_ratings"}}
)
end
end