mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
4d2d29d976
feat: support configuring polymorphic references feat: support `distinct` Ash queries
56 lines
2.5 KiB
Elixir
56 lines
2.5 KiB
Elixir
defmodule AshPostgres.Reference do
|
|
@moduledoc """
|
|
Contains configuration for a database reference
|
|
"""
|
|
defstruct [:relationship, :on_delete, :on_update, :name]
|
|
|
|
def schema do
|
|
[
|
|
relationship: [
|
|
type: :atom,
|
|
required: true,
|
|
doc: "The relationship to be configured"
|
|
],
|
|
on_delete: [
|
|
type: {:one_of, [:delete, :nilify, :nothing, :restrict]},
|
|
doc: """
|
|
What should happen to records of this resource when the referenced record of the *destination* resource is deleted.
|
|
|
|
The difference between `:nothing` and `:restrict` is subtle and, if you are unsure, choose `:nothing` (the default behavior).
|
|
`:restrict` will prevent the deletion from happening *before* the end of the database transaction, whereas `:nothing` allows the
|
|
transaction to complete before doing so. This allows for things like deleting the destination row and *then* deleting the source
|
|
row.
|
|
|
|
## Important!
|
|
|
|
No resource logic is applied with this operation! No authorization rules or validations take place, and no notifications are issued.
|
|
This operation happens *directly* in the database.
|
|
|
|
This option is called `on_delete`, instead of `on_destroy`, because it is hooking into the database level deletion, *not*
|
|
a `destroy` action in your resource.
|
|
"""
|
|
],
|
|
on_update: [
|
|
type: {:one_of, [:update, :nilify, :nothing, :restrict]},
|
|
doc: """
|
|
What should happen to records of this resource when the referenced destination_field of the *destination* record is update.
|
|
|
|
The difference between `:nothing` and `:restrict` is subtle and, if you are unsure, choose `:nothing` (the default behavior).
|
|
`:restrict` will prevent the deletion from happening *before* the end of the database transaction, whereas `:nothing` allows the
|
|
transaction to complete before doing so. This allows for things like updating the destination row and *then* updating the reference
|
|
as long as you are in a transaction.
|
|
|
|
## Important!
|
|
|
|
No resource logic is applied with this operation! No authorization rules or validations take place, and no notifications are issued.
|
|
This operation happens *directly* in the database.
|
|
"""
|
|
],
|
|
name: [
|
|
type: :string,
|
|
doc:
|
|
"The name of the foreign key to generate in the database. Defaults to <table>_<source_field>_fkey"
|
|
]
|
|
]
|
|
end
|
|
end
|