2020-09-11 12:26:47 +12:00
|
|
|
defmodule AshPostgres.Test.Comment do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
table "comments"
|
|
|
|
repo AshPostgres.TestRepo
|
2021-04-01 19:19:30 +13:00
|
|
|
|
|
|
|
references do
|
|
|
|
reference(:post, on_delete: :delete, on_update: :update, name: "special_name_fkey")
|
|
|
|
end
|
2020-09-11 12:26:47 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
2021-01-13 14:22:28 +13:00
|
|
|
read(:read)
|
2021-02-01 10:39:59 +13:00
|
|
|
|
|
|
|
create :create do
|
2021-02-06 12:59:33 +13:00
|
|
|
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
|
2020-09-11 12:26:47 +12:00
|
|
|
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)
|
2021-11-14 07:55:49 +13:00
|
|
|
attribute(:arbitrary_timestamp, :utc_datetime_usec)
|
2022-02-10 05:49:19 +13:00
|
|
|
create_timestamp(:created_at, writable?: true)
|
2020-09-11 12:26:47 +12:00
|
|
|
end
|
|
|
|
|
2021-12-18 07:25:14 +13:00
|
|
|
aggregates do
|
|
|
|
first(:post_category, :post, :category)
|
|
|
|
end
|
|
|
|
|
2020-09-11 12:26:47 +12:00
|
|
|
relationships do
|
2021-01-13 14:22:28 +13:00
|
|
|
belongs_to(:post, AshPostgres.Test.Post)
|
2021-06-04 17:48:35 +12:00
|
|
|
belongs_to(:author, AshPostgres.Test.Author)
|
2021-01-29 13:42:55 +13:00
|
|
|
|
|
|
|
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"}}
|
2021-01-29 13:42:55 +13:00
|
|
|
)
|
2020-09-11 12:26:47 +12:00
|
|
|
end
|
|
|
|
end
|