Add relationships to server for all resources.

This commit is contained in:
2025-03-23 12:08:42 +02:00
parent b49b7c954c
commit 97758de39c
16 changed files with 1039 additions and 0 deletions
@@ -157,6 +157,8 @@ defmodule DecentralisedBookIndex.Metadata.Author do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
belongs_to :author_alias_registry, Metadata.AuthorAliasRegistry do
attribute_writable? true
end
@@ -4,6 +4,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorAliasRegistry do
domain: DecentralisedBookIndex.Metadata,
data_layer: AshPostgres.DataLayer
alias DecentralisedBookIndex.Metadata
postgres do
table "author_alias_registries"
repo DecentralisedBookIndex.Repo
@@ -26,6 +28,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorAliasRegistry do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
has_many :authors, DecentralisedBookIndex.Metadata.Author
end
end
@@ -44,6 +44,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
accept [:order, :role]
argument :author_id, :uuid
require_atomic? false
change fn changeset, _ ->
author_id = changeset.arguments.author_id
@@ -75,6 +77,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
belongs_to :book, Metadata.Book do
allow_nil? true
end
@@ -148,6 +148,8 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
belongs_to :book_editions_registry, Metadata.BookEditionsRegistry
belongs_to :publisher, Metadata.Publisher
@@ -4,6 +4,8 @@ defmodule DecentralisedBookIndex.Metadata.BookEditionsRegistry do
domain: DecentralisedBookIndex.Metadata,
data_layer: AshPostgres.DataLayer
alias DecentralisedBookIndex.Metadata
postgres do
table "book_editions_registries"
repo DecentralisedBookIndex.Repo
@@ -26,6 +28,8 @@ defmodule DecentralisedBookIndex.Metadata.BookEditionsRegistry do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
has_many :authors, DecentralisedBookIndex.Metadata.Book
end
end
@@ -57,6 +57,8 @@ defmodule DecentralisedBookIndex.Metadata.BookId do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
belongs_to :book, Metadata.Book do
allow_nil? true
end
@@ -4,6 +4,8 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do
domain: DecentralisedBookIndex.Metadata,
data_layer: AshPostgres.DataLayer
alias DecentralisedBookIndex.Metadata
postgres do
table "dbi_servers"
repo DecentralisedBookIndex.Repo
@@ -38,4 +40,16 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do
timestamps()
end
relationships do
has_many :author, Metadata.Author
has_many :author_alias_registries, Metadata.AuthorAliasRegistry
has_many :author_roles, Metadata.AuthorRole
has_many :books, Metadata.Book
has_many :bids, Metadata.BookId
has_many :book_editions_registries, Metadata.BookEditionsRegistry
has_many :publisher, Metadata.Publisher
end
end
@@ -39,6 +39,8 @@ defmodule DecentralisedBookIndex.Metadata.Publisher do
end
relationships do
belongs_to :dbi_server, Metadata.DBIServer
has_many :books, Metadata.Book
end
end