Add the author alias registry to manage alias relationship.
Add datalayer and migrations.
This commit is contained in:
@@ -10,7 +10,17 @@ defmodule DecentralisedBookIndex.Metadata.Author do
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [:read]
|
||||
defaults [:read, :update, :destroy]
|
||||
|
||||
update :add_author_to_alias_registry do
|
||||
accept [:author_alias_registry_id]
|
||||
end
|
||||
|
||||
create :create do
|
||||
primary? true
|
||||
accept [:name, :description, :author_alias_registry_id]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
@@ -28,4 +38,10 @@ defmodule DecentralisedBookIndex.Metadata.Author do
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
relationships do
|
||||
belongs_to :author_alias_registry, DecentralisedBookIndex.Metadata.AuthorAliasRegistry do
|
||||
attribute_writable? true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
defmodule DecentralisedBookIndex.Metadata.AuthorAliasRegistry do
|
||||
use Ash.Resource,
|
||||
otp_app: :decentralised_book_index,
|
||||
domain: DecentralisedBookIndex.Metadata,
|
||||
data_layer: AshPostgres.DataLayer
|
||||
|
||||
postgres do
|
||||
table "author_alias_registries"
|
||||
repo DecentralisedBookIndex.Repo
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [:read, :create, :update, :destroy]
|
||||
|
||||
read :by_id do
|
||||
argument :id, :uuid, allow_nil?: false
|
||||
get? true
|
||||
filter expr(id == ^arg(:id))
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
relationships do
|
||||
has_many :authors, DecentralisedBookIndex.Metadata.Author
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user