mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
improvement: add relationships to underlying ecto schemas for better escape hatches
This commit is contained in:
parent
bfc592adab
commit
2787b5074b
1 changed files with 37 additions and 0 deletions
|
@ -156,6 +156,43 @@ defmodule Ash.Schema do
|
|||
|
||||
for relationship <- Ash.Resource.Info.relationships(__MODULE__),
|
||||
relationship.name not in Ash.Resource.reserved_names() do
|
||||
case relationship do
|
||||
%{no_attributes?: true} ->
|
||||
:ok
|
||||
|
||||
%{manual?: true} ->
|
||||
:ok
|
||||
|
||||
%{manual: manual} when not is_nil(manual) ->
|
||||
:ok
|
||||
|
||||
%{type: :belongs_to} ->
|
||||
belongs_to relationship.name, relationship.destination,
|
||||
define_field: false,
|
||||
references: relationship.destination_attribute,
|
||||
foreign_key: relationship.source_attribute
|
||||
|
||||
%{type: :has_many} ->
|
||||
has_many relationship.name, relationship.destination,
|
||||
foreign_key: relationship.destination_attribute,
|
||||
references: relationship.source_attribute
|
||||
|
||||
%{type: :has_one} ->
|
||||
has_one relationship.name, relationship.destination,
|
||||
foreign_key: relationship.destination_attribute,
|
||||
references: relationship.source_attribute
|
||||
|
||||
%{type: :many_to_many} ->
|
||||
many_to_many relationship.name, relationship.destination,
|
||||
join_through: relationship.through,
|
||||
join_keys: [
|
||||
{relationship.source_attribute_on_join_resource,
|
||||
relationship.source_attribute},
|
||||
{relationship.destination_attribute_on_join_resource,
|
||||
relationship.destination_attribute}
|
||||
]
|
||||
end
|
||||
|
||||
Module.put_attribute(
|
||||
__MODULE__,
|
||||
:ash_struct_fields,
|
||||
|
|
Loading…
Reference in a new issue