2021-04-30 09:31:19 +12:00
|
|
|
defmodule AshPostgres.Test.PostLink do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
2024-03-28 09:52:28 +13:00
|
|
|
domain: AshPostgres.Test.Domain,
|
2021-04-30 09:31:19 +12:00
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
table "post_links"
|
|
|
|
repo AshPostgres.TestRepo
|
|
|
|
end
|
|
|
|
|
2022-04-20 03:08:28 +12:00
|
|
|
actions do
|
2024-03-28 09:52:28 +13:00
|
|
|
default_accept(:*)
|
|
|
|
|
2022-04-20 03:08:28 +12:00
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
|
|
end
|
|
|
|
|
2022-10-15 18:03:16 +13:00
|
|
|
identities do
|
|
|
|
identity(:unique_link, [:source_post_id, :destination_post_id])
|
|
|
|
end
|
|
|
|
|
2022-12-05 07:39:58 +13:00
|
|
|
attributes do
|
|
|
|
attribute :state, :atom do
|
2024-03-28 09:52:28 +13:00
|
|
|
public?(true)
|
2022-12-05 07:39:58 +13:00
|
|
|
constraints(one_of: [:active, :archived])
|
|
|
|
default(:active)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-30 09:31:19 +12:00
|
|
|
relationships do
|
|
|
|
belongs_to :source_post, AshPostgres.Test.Post do
|
2024-03-28 09:52:28 +13:00
|
|
|
public?(true)
|
2022-09-15 04:59:01 +12:00
|
|
|
allow_nil?(false)
|
2021-04-30 09:31:19 +12:00
|
|
|
primary_key?(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
belongs_to :destination_post, AshPostgres.Test.Post do
|
2024-03-28 09:52:28 +13:00
|
|
|
public?(true)
|
2022-09-15 04:59:01 +12:00
|
|
|
allow_nil?(false)
|
2021-04-30 09:31:19 +12:00
|
|
|
primary_key?(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|