ash_postgres/test/support/resources/comment.ex
Zach Daniel 4d2d29d976 feat: support configuring references
feat: support configuring polymorphic references
feat: support `distinct` Ash queries
2021-04-01 02:19:30 -04:00

38 lines
802 B
Elixir

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
read(:read)
create :create do
argument(:rating, :map)
change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create))
end
end
attributes do
uuid_primary_key(:id)
attribute(:title, :string)
end
relationships do
belongs_to(:post, AshPostgres.Test.Post)
has_many(:ratings, AshPostgres.Test.Rating,
destination_field: :resource_id,
context: %{data_layer: %{table: "comment_ratings"}}
)
end
end