2021-04-01 19:19:30 +13:00
defmodule AshPostgres.Reference do
2023-09-23 08:14:25 +12:00
@moduledoc " Represents the configuration of a reference (i.e foreign key). "
2023-11-21 10:52:50 +13:00
defstruct [
:relationship ,
:on_delete ,
:on_update ,
:name ,
:match_with ,
:match_type ,
:deferrable ,
ignore? : false
]
2021-04-01 19:19:30 +13:00
def schema do
[
relationship : [
type : :atom ,
required : true ,
doc : " The relationship to be configured "
] ,
2022-05-24 18:11:54 +12:00
ignore? : [
type : :boolean ,
doc :
" If set to true, no reference is created for the given relationship. This is useful if you need to define it in some custom way "
] ,
2021-04-01 19:19:30 +13:00
on_delete : [
2024-05-17 12:18:17 +12:00
type :
{ :or ,
[
{ :one_of , [ :delete , :nilify , :nothing , :restrict ] } ,
{ :tagged_tuple , :nilify , { :wrap_list , :atom } }
] } ,
2021-04-01 19:19:30 +13:00
doc : """
What should happen to records of this resource when the referenced record of the * destination * resource is deleted .
"""
] ,
on_update : [
type : { :one_of , [ :update , :nilify , :nothing , :restrict ] } ,
doc : """
2022-08-19 06:56:36 +12:00
What should happen to records of this resource when the referenced destination_attribute of the * destination * record is update .
2021-04-01 19:19:30 +13:00
"""
] ,
2023-07-15 08:24:57 +12:00
deferrable : [
type : { :one_of , [ false , true , :initially ] } ,
default : false ,
doc : """
Wether or not the constraint is deferrable . This only affects the migration generator .
"""
] ,
2021-04-01 19:19:30 +13:00
name : [
type : :string ,
doc :
2022-08-19 06:56:36 +12:00
" The name of the foreign key to generate in the database. Defaults to <table>_<source_attribute>_fkey "
2023-11-21 10:52:50 +13:00
] ,
match_with : [
type : :non_empty_keyword_list ,
doc :
" Defines additional keys to the foreign key in order to build a composite foreign key. The key should be the name of the source attribute (in the current resource), the value the name of the destination attribute. "
] ,
match_type : [
type : { :one_of , [ :simple , :partial , :full ] } ,
doc : " select if the match is `:simple`, `:partial`, or `:full` "
2021-04-01 19:19:30 +13:00
]
]
end
end