mirror of
https://github.com/ash-project/ash.git
synced 2024-09-21 14:03:04 +12:00
13614 lines
314 KiB
Text
13614 lines
314 KiB
Text
<!--
|
|
This file was generated by Spark. Do not edit it by hand.
|
|
-->
|
|
# DSL: Ash.Resource.Dsl
|
|
|
|
|
|
|
|
## attributes
|
|
A section for declaring attributes on the resource.
|
|
|
|
|
|
### Nested DSLs
|
|
* [attribute](#attributes-attribute)
|
|
* [create_timestamp](#attributes-create_timestamp)
|
|
* [update_timestamp](#attributes-update_timestamp)
|
|
* [integer_primary_key](#attributes-integer_primary_key)
|
|
* [uuid_primary_key](#attributes-uuid_primary_key)
|
|
|
|
|
|
### Examples
|
|
```
|
|
attributes do
|
|
uuid_primary_key :id
|
|
|
|
attribute :first_name, :string do
|
|
allow_nil? false
|
|
end
|
|
|
|
attribute :last_name, :string do
|
|
allow_nil? false
|
|
end
|
|
|
|
attribute :email, :string do
|
|
allow_nil? false
|
|
|
|
constraints [
|
|
match: ~r/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/
|
|
]
|
|
end
|
|
|
|
attribute :type, :atom do
|
|
constraints [
|
|
one_of: [:admin, :teacher, :student]
|
|
]
|
|
end
|
|
|
|
create_timestamp :inserted_at
|
|
update_timestamp :updated_at
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## attributes.attribute
|
|
```elixir
|
|
attribute name, type
|
|
```
|
|
|
|
|
|
Declares an attribute on the resource.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
attribute :name, :string do
|
|
allow_nil? false
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-name" href="#attributes-attribute-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-type" href="#attributes-attribute-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-constraints" href="#attributes-attribute-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-description" href="#attributes-attribute-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-sensitive?" href="#attributes-attribute-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-source" href="#attributes-attribute-source">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the field should be mapped to a different name in the data layer. Support varies by data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-always_select?" href="#attributes-attribute-always_select?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_select?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-primary_key?" href="#attributes-attribute-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-allow_nil?" href="#attributes-attribute-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be set to nil. If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-generated?" href="#attributes-attribute-generated?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
generated?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value may be generated by the data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-writable?" href="#attributes-attribute-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-private?" href="#attributes-attribute-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-default" href="#attributes-attribute-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all creates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-update_default" href="#attributes-attribute-update_default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
update_default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all updates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-filterable?" href="#attributes-attribute-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be referenced in filters.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-attribute-match_other_defaults?" href="#attributes-attribute-match_other_defaults?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
match_other_defaults?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Attribute`
|
|
|
|
## attributes.create_timestamp
|
|
```elixir
|
|
create_timestamp name
|
|
```
|
|
|
|
|
|
Declares a non-writable attribute with a create default of `&DateTime.utc_now/0`
|
|
|
|
Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except it sets
|
|
the following different defaults:
|
|
|
|
writable? false
|
|
private? true
|
|
default &DateTime.utc_now/0
|
|
match_other_defaults? true
|
|
type Ash.Type.UTCDatetimeUsec
|
|
allow_nil? false
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
create_timestamp :inserted_at
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-name" href="#attributes-create_timestamp-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-type" href="#attributes-create_timestamp-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Ash.Type.UtcDatetimeUsec</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-constraints" href="#attributes-create_timestamp-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-description" href="#attributes-create_timestamp-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-sensitive?" href="#attributes-create_timestamp-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-source" href="#attributes-create_timestamp-source">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the field should be mapped to a different name in the data layer. Support varies by data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-always_select?" href="#attributes-create_timestamp-always_select?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_select?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-primary_key?" href="#attributes-create_timestamp-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-allow_nil?" href="#attributes-create_timestamp-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be set to nil. If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-generated?" href="#attributes-create_timestamp-generated?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
generated?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value may be generated by the data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-writable?" href="#attributes-create_timestamp-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-private?" href="#attributes-create_timestamp-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-default" href="#attributes-create_timestamp-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">&DateTime.utc_now/0</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all creates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-update_default" href="#attributes-create_timestamp-update_default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
update_default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all updates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-filterable?" href="#attributes-create_timestamp-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be referenced in filters.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-create_timestamp-match_other_defaults?" href="#attributes-create_timestamp-match_other_defaults?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
match_other_defaults?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Attribute`
|
|
|
|
## attributes.update_timestamp
|
|
```elixir
|
|
update_timestamp name
|
|
```
|
|
|
|
|
|
Declares a non-writable attribute with a create and update default of `&DateTime.utc_now/0`
|
|
|
|
Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except it sets
|
|
the following different defaults:
|
|
|
|
writable? false
|
|
private? true
|
|
default &DateTime.utc_now/0
|
|
match_other_defaults? true
|
|
update_default &DateTime.utc_now/0
|
|
type Ash.Type.UTCDatetimeUsec
|
|
allow_nil? false
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
update_timestamp :updated_at
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-name" href="#attributes-update_timestamp-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-type" href="#attributes-update_timestamp-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Ash.Type.UtcDatetimeUsec</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-constraints" href="#attributes-update_timestamp-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-description" href="#attributes-update_timestamp-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-sensitive?" href="#attributes-update_timestamp-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-source" href="#attributes-update_timestamp-source">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the field should be mapped to a different name in the data layer. Support varies by data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-always_select?" href="#attributes-update_timestamp-always_select?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_select?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-primary_key?" href="#attributes-update_timestamp-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-allow_nil?" href="#attributes-update_timestamp-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be set to nil. If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-generated?" href="#attributes-update_timestamp-generated?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
generated?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value may be generated by the data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-writable?" href="#attributes-update_timestamp-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-private?" href="#attributes-update_timestamp-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-default" href="#attributes-update_timestamp-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">&DateTime.utc_now/0</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all creates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-update_default" href="#attributes-update_timestamp-update_default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
update_default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">&DateTime.utc_now/0</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all updates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-filterable?" href="#attributes-update_timestamp-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be referenced in filters.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-update_timestamp-match_other_defaults?" href="#attributes-update_timestamp-match_other_defaults?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
match_other_defaults?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Attribute`
|
|
|
|
## attributes.integer_primary_key
|
|
```elixir
|
|
integer_primary_key name
|
|
```
|
|
|
|
|
|
Declares a generated, non writable, non-nil, primary key column of type integer.
|
|
|
|
Generated integer primary keys must be supported by the data layer.
|
|
|
|
Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except for `allow_nil?`, but it sets
|
|
the following different defaults:
|
|
|
|
writable? false
|
|
primary_key? true
|
|
generated? true
|
|
type :integer
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
integer_primary_key :id
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-name" href="#attributes-integer_primary_key-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-type" href="#attributes-integer_primary_key-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:integer</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-constraints" href="#attributes-integer_primary_key-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-description" href="#attributes-integer_primary_key-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-sensitive?" href="#attributes-integer_primary_key-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-source" href="#attributes-integer_primary_key-source">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the field should be mapped to a different name in the data layer. Support varies by data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-always_select?" href="#attributes-integer_primary_key-always_select?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_select?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-primary_key?" href="#attributes-integer_primary_key-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-generated?" href="#attributes-integer_primary_key-generated?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
generated?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value may be generated by the data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-writable?" href="#attributes-integer_primary_key-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-private?" href="#attributes-integer_primary_key-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-default" href="#attributes-integer_primary_key-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all creates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-update_default" href="#attributes-integer_primary_key-update_default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
update_default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all updates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-filterable?" href="#attributes-integer_primary_key-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be referenced in filters.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-integer_primary_key-match_other_defaults?" href="#attributes-integer_primary_key-match_other_defaults?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
match_other_defaults?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Attribute`
|
|
|
|
## attributes.uuid_primary_key
|
|
```elixir
|
|
uuid_primary_key name
|
|
```
|
|
|
|
|
|
Declares a non writable, non-nil, primary key column of type `uuid`, which defaults to `Ash.UUID.generate/0`.
|
|
|
|
Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except for `allow_nil?`, but it sets
|
|
the following different defaults:
|
|
|
|
writable? false
|
|
default &Ash.UUID.generate/0
|
|
primary_key? true
|
|
generated? true
|
|
type :uuid
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
uuid_primary_key :id
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-name" href="#attributes-uuid_primary_key-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-type" href="#attributes-uuid_primary_key-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:uuid</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-constraints" href="#attributes-uuid_primary_key-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-description" href="#attributes-uuid_primary_key-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the attribute.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-sensitive?" href="#attributes-uuid_primary_key-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-source" href="#attributes-uuid_primary_key-source">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the field should be mapped to a different name in the data layer. Support varies by data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-always_select?" href="#attributes-uuid_primary_key-always_select?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_select?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-primary_key?" href="#attributes-uuid_primary_key-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-generated?" href="#attributes-uuid_primary_key-generated?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
generated?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value may be generated by the data layer.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-writable?" href="#attributes-uuid_primary_key-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-private?" href="#attributes-uuid_primary_key-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-default" href="#attributes-uuid_primary_key-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">&Ash.UUID.generate/0</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all creates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-update_default" href="#attributes-uuid_primary_key-update_default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
update_default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A value to be set on all updates, unless a value is being provided already.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-filterable?" href="#attributes-uuid_primary_key-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the attribute can be referenced in filters.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="attributes-uuid_primary_key-match_other_defaults?" href="#attributes-uuid_primary_key-match_other_defaults?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
match_other_defaults?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Attribute`
|
|
|
|
|
|
|
|
|
|
## relationships
|
|
A section for declaring relationships on the resource.
|
|
|
|
Relationships are a core component of resource oriented design. Many components of Ash
|
|
will use these relationships. A simple use case is loading relationships (done via the `Ash.Query.load/2`).
|
|
|
|
See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [has_one](#relationships-has_one)
|
|
* [has_many](#relationships-has_many)
|
|
* [many_to_many](#relationships-many_to_many)
|
|
* [belongs_to](#relationships-belongs_to)
|
|
|
|
|
|
### Examples
|
|
```
|
|
relationships do
|
|
belongs_to :post, MyApp.Post do
|
|
primary_key? true
|
|
end
|
|
|
|
belongs_to :category, MyApp.Category do
|
|
primary_key? true
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
```
|
|
relationships do
|
|
belongs_to :author, MyApp.Author
|
|
|
|
many_to_many :categories, MyApp.Category do
|
|
through MyApp.PostCategory
|
|
destination_attribute_on_join_resource :category_id
|
|
source_attribute_on_join_resource :post_id
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
```
|
|
relationships do
|
|
has_many :posts, MyApp.Post do
|
|
destination_attribute :author_id
|
|
end
|
|
|
|
has_many :composite_key_posts, MyApp.CompositeKeyPost do
|
|
destination_attribute :author_id
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## relationships.has_one
|
|
```elixir
|
|
has_one name, destination
|
|
```
|
|
|
|
|
|
Declares a `has_one` relationship. In a relational database, the foreign key would be on the *other* table.
|
|
|
|
Generally speaking, a `has_one` also implies that the destination table is unique on that foreign key.
|
|
|
|
See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
# In a resource called `Word`
|
|
has_one :dictionary_entry, DictionaryEntry do
|
|
source_attribute :text
|
|
destination_attribute :word_text
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-name" href="#relationships-has_one-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-destination" href="#relationships-has_one-destination">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-manual" href="#relationships-has_one-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A module that implements `Ash.Resource.ManualRelationship`. Also accepts a 2 argument function that takes the source records and the context.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-no_attributes?" href="#relationships-has_one-no_attributes?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
no_attributes?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
All existing entities are considered related, i.e this relationship is not based on any fields, and `source_attribute` and `destination_attribute` are ignored. See the See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-allow_nil?" href="#relationships-has_one-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Marks the relationship as required. Has no effect on validations, but can inform extensions that there will always be a related entity.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-from_many?" href="#relationships-has_one-from_many?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
from_many?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Signal that this relationship is actually a `has_many` where the first record is given via the `sort`. This will allow data layers to properly deduplicate when necessary.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-description" href="#relationships-has_one-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-destination_attribute" href="#relationships-has_one-destination_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the related resource that should match the `source_attribute` configured on this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-validate_destination_attribute?" href="#relationships-has_one-validate_destination_attribute?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validate_destination_attribute?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to validate that the destination field exists on the destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-source_attribute" href="#relationships-has_one-source_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:id</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field on this resource that should match the `destination_attribute` on the related resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-relationship_context" href="#relationships-has_one-relationship_context">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_context
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Context to be set on any queries or changesets generated for managing or querying this relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-private?" href="#relationships-has_one-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-not_found_message" href="#relationships-has_one-not_found_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
not_found_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-writable?" href="#relationships-has_one-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship may be managed.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-read_action" href="#relationships-has_one-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action on the destination resource to use when loading data and filtering.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-api" href="#relationships-has_one-api">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
api
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The API module to use when working with the related entity.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-filter" href="#relationships-has_one-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to be applied when reading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-filterable?" href="#relationships-has_one-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `false`, the relationship will not be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-sort" href="#relationships-has_one-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort statement to be applied when loading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-could_be_related_at_creation?" href="#relationships-has_one-could_be_related_at_creation?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
could_be_related_at_creation?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not related values may exist for this relationship at creation.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_one-violation_message" href="#relationships-has_one-violation_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
violation_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on destroy.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Relationships.HasOne`
|
|
|
|
## relationships.has_many
|
|
```elixir
|
|
has_many name, destination
|
|
```
|
|
|
|
|
|
Declares a `has_many` relationship. There can be any number of related entities.
|
|
|
|
See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
# In a resource called `Word`
|
|
has_many :definitions, DictionaryDefinition do
|
|
source_attribute :text
|
|
destination_attribute :word_text
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-name" href="#relationships-has_many-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-destination" href="#relationships-has_many-destination">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-manual" href="#relationships-has_many-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A module that implements `Ash.Resource.ManualRelationship`. Also accepts a 2 argument function that takes the source records and the context.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-no_attributes?" href="#relationships-has_many-no_attributes?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
no_attributes?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
All existing entities are considered related, i.e this relationship is not based on any fields, and `source_attribute` and `destination_attribute` are ignored. See the See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-description" href="#relationships-has_many-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-destination_attribute" href="#relationships-has_many-destination_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the related resource that should match the `source_attribute` configured on this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-validate_destination_attribute?" href="#relationships-has_many-validate_destination_attribute?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validate_destination_attribute?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to validate that the destination field exists on the destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-source_attribute" href="#relationships-has_many-source_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:id</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field on this resource that should match the `destination_attribute` on the related resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-relationship_context" href="#relationships-has_many-relationship_context">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_context
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Context to be set on any queries or changesets generated for managing or querying this relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-private?" href="#relationships-has_many-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-not_found_message" href="#relationships-has_many-not_found_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
not_found_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-writable?" href="#relationships-has_many-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship may be managed.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-read_action" href="#relationships-has_many-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action on the destination resource to use when loading data and filtering.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-api" href="#relationships-has_many-api">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
api
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The API module to use when working with the related entity.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-filter" href="#relationships-has_many-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to be applied when reading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-filterable?" href="#relationships-has_many-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `false`, the relationship will not be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-sort" href="#relationships-has_many-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort statement to be applied when loading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-could_be_related_at_creation?" href="#relationships-has_many-could_be_related_at_creation?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
could_be_related_at_creation?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not related values may exist for this relationship at creation.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-has_many-violation_message" href="#relationships-has_many-violation_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
violation_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on destroy.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Relationships.HasMany`
|
|
|
|
## relationships.many_to_many
|
|
```elixir
|
|
many_to_many name, destination
|
|
```
|
|
|
|
|
|
Declares a `many_to_many` relationship. Many to many relationships require a join resource.
|
|
|
|
A join resource is a resource that consists of a relationship to the source and destination of the many to many.
|
|
|
|
See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
# In a resource called `Word`
|
|
many_to_many :books, Book do
|
|
through BookWord
|
|
source_attribute :text
|
|
source_attribute_on_join_resource :word_text
|
|
destination_attribute :id
|
|
destination_attribute_on_join_resource :book_id
|
|
end
|
|
|
|
# And in `BookWord` (the join resource)
|
|
belongs_to :book, Book, primary_key?: true, allow_nil?: false
|
|
belongs_to :word, Word, primary_key?: true, allow_nil?: false
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-name" href="#relationships-many_to_many-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-destination" href="#relationships-many_to_many-destination">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-through" href="#relationships-many_to_many-through">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
through
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The resource to use as the join resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-source_attribute_on_join_resource" href="#relationships-many_to_many-source_attribute_on_join_resource">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source_attribute_on_join_resource
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the join resource that should line up with `source_attribute` on this resource. Defaults to `<snake_cased_last_part_of_source_module_name>_id`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-destination_attribute_on_join_resource" href="#relationships-many_to_many-destination_attribute_on_join_resource">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination_attribute_on_join_resource
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the join resource that should line up with `destination_attribute` on the related resource. Defaults to `<snake_cased_last_part_of_destination_module_name>_id`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-join_relationship" href="#relationships-many_to_many-join_relationship">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
join_relationship
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The has_many relationship to the join resource. Defaults to `<relationship_name>_join_assoc`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-description" href="#relationships-many_to_many-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-destination_attribute" href="#relationships-many_to_many-destination_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:id</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the related resource that should match the `source_attribute` configured on this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-validate_destination_attribute?" href="#relationships-many_to_many-validate_destination_attribute?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validate_destination_attribute?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to validate that the destination field exists on the destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-source_attribute" href="#relationships-many_to_many-source_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:id</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field on this resource that should match the `destination_attribute` on the related resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-relationship_context" href="#relationships-many_to_many-relationship_context">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_context
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Context to be set on any queries or changesets generated for managing or querying this relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-private?" href="#relationships-many_to_many-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-not_found_message" href="#relationships-many_to_many-not_found_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
not_found_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-writable?" href="#relationships-many_to_many-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship may be managed.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-read_action" href="#relationships-many_to_many-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action on the destination resource to use when loading data and filtering.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-api" href="#relationships-many_to_many-api">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
api
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The API module to use when working with the related entity.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-filter" href="#relationships-many_to_many-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to be applied when reading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-filterable?" href="#relationships-many_to_many-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `false`, the relationship will not be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-sort" href="#relationships-many_to_many-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort statement to be applied when loading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-could_be_related_at_creation?" href="#relationships-many_to_many-could_be_related_at_creation?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
could_be_related_at_creation?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not related values may exist for this relationship at creation.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-many_to_many-violation_message" href="#relationships-many_to_many-violation_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
violation_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on destroy.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Relationships.ManyToMany`
|
|
|
|
## relationships.belongs_to
|
|
```elixir
|
|
belongs_to name, destination
|
|
```
|
|
|
|
|
|
Declares a `belongs_to` relationship. In a relational database, the foreign key would be on the *source* table.
|
|
|
|
This creates a field on the resource with the corresponding name and type, unless `define_attribute?: false` is provided.
|
|
|
|
See the [relationships guide](/documentation/topics/relationships.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
# In a resource called `Word`
|
|
belongs_to :dictionary_entry, DictionaryEntry do
|
|
source_attribute :text,
|
|
destination_attribute :word_text
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-name" href="#relationships-belongs_to-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-destination" href="#relationships-belongs_to-destination">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-primary_key?" href="#relationships-belongs_to-primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the generated attribute is, or is part of, the primary key of a resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-allow_nil?" href="#relationships-belongs_to-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether this relationship must always be present, e.g: must be included on creation, and never removed (it may be modified). The generated attribute will not allow nil values.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-attribute_writable?" href="#relationships-belongs_to-attribute_writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
attribute_writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether the generated attribute will be marked as public & writable.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-define_attribute?" href="#relationships-belongs_to-define_attribute?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
define_attribute?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `false` an attribute is not created on the resource for this relationship, and one must be manually added in `attributes`, invalidating many other options.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-attribute_type" href="#relationships-belongs_to-attribute_type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
attribute_type
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:uuid</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the generated created attribute. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-description" href="#relationships-belongs_to-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the relationship
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-destination_attribute" href="#relationships-belongs_to-destination_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
destination_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:id</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The attribute on the related resource that should match the `source_attribute` configured on this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-validate_destination_attribute?" href="#relationships-belongs_to-validate_destination_attribute?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validate_destination_attribute?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to validate that the destination field exists on the destination resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-source_attribute" href="#relationships-belongs_to-source_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
source_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field on this resource that should match the `destination_attribute` on the related resource. - Defaults to <name>_id
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-relationship_context" href="#relationships-belongs_to-relationship_context">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_context
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Context to be set on any queries or changesets generated for managing or querying this relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-private?" href="#relationships-belongs_to-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-not_found_message" href="#relationships-belongs_to-not_found_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
not_found_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-writable?" href="#relationships-belongs_to-writable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
writable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the relationship may be managed.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-read_action" href="#relationships-belongs_to-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action on the destination resource to use when loading data and filtering.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-api" href="#relationships-belongs_to-api">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
api
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The API module to use when working with the related entity.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-filter" href="#relationships-belongs_to-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to be applied when reading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-filterable?" href="#relationships-belongs_to-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `false`, the relationship will not be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-sort" href="#relationships-belongs_to-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort statement to be applied when loading the relationship.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="relationships-belongs_to-violation_message" href="#relationships-belongs_to-violation_message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
violation_message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A message to show if there is a conflict with this relationship in the database on destroy.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Relationships.BelongsTo`
|
|
|
|
|
|
|
|
|
|
## actions
|
|
A section for declaring resource actions.
|
|
|
|
All manipulation of data through the underlying data layer happens through actions.
|
|
There are four types of action: `create`, `read`, `update`, and `destroy`. You may
|
|
recognize these from the acronym `CRUD`. You can have multiple actions of the same
|
|
type, as long as they have different names. This is the primary mechanism for customizing
|
|
your resources to conform to your business logic. It is normal and expected to have
|
|
multiple actions of each type in a large application.
|
|
|
|
|
|
### Nested DSLs
|
|
* [action](#actions-action)
|
|
* argument
|
|
* [create](#actions-create)
|
|
* change
|
|
* validate
|
|
* argument
|
|
* metadata
|
|
* [read](#actions-read)
|
|
* argument
|
|
* prepare
|
|
* pagination
|
|
* metadata
|
|
* [update](#actions-update)
|
|
* change
|
|
* validate
|
|
* metadata
|
|
* argument
|
|
* [destroy](#actions-destroy)
|
|
* change
|
|
* validate
|
|
* metadata
|
|
* argument
|
|
|
|
|
|
### Examples
|
|
```
|
|
actions do
|
|
create :signup do
|
|
argument :password, :string
|
|
argument :password_confirmation, :string
|
|
validate confirm(:password, :password_confirmation)
|
|
change {MyApp.HashPassword, []} # A custom implemented Change
|
|
end
|
|
|
|
read :me do
|
|
# An action that auto filters to only return the user for the current user
|
|
filter [id: actor(:id)]
|
|
end
|
|
|
|
update :update do
|
|
accept [:first_name, :last_name]
|
|
end
|
|
|
|
destroy do
|
|
change set_attribute(:deleted_at, &DateTime.utc_now/0)
|
|
# This tells it that even though this is a delete action, it
|
|
# should be treated like an update because `deleted_at` is set.
|
|
# This should be coupled with a `base_filter` on the resource
|
|
# or with the read actions having a `filter` for `is_nil: :deleted_at`
|
|
soft? true
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-defaults" href="#actions-defaults">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
defaults
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(:create | :read | :update | :destroy)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Creates a simple action of each specified type, with the same name as the type. These will be `primary?` unless one already exists for that type. Embedded resources, however, have a default of all resource types.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-default_accept" href="#actions-default_accept">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default_accept
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value for the `accept` option for each action. Defaults to all public attributes.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
## actions.action
|
|
```elixir
|
|
action name, returns
|
|
```
|
|
|
|
|
|
Declares a generic action. A combination of arguments, a return type and a run function.
|
|
|
|
For calling this action, see the `Ash.Api` documentation.
|
|
|
|
|
|
### Nested DSLs
|
|
* [argument](#actions-action-argument)
|
|
|
|
|
|
### Examples
|
|
```
|
|
action :top_user_emails, {:array, :string} do
|
|
argument :limit, :integer, default: 10, allow_nil?: false
|
|
run fn input, context ->
|
|
with {:ok, top_users} <- top_users(input.limit) do
|
|
{:ok, Enum.map(top_users, &(&1.email))}
|
|
end
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-name" href="#actions-action-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-returns" href="#actions-action-returns">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
returns
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The return type of the action. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-constraints" href="#actions-action-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints for the return type. See the [constriants topic](/documentation/topics/constraints.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-allow_nil?" href="#actions-action-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action can return nil. Unlike attributes & arguments, this defaults to `false`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-run" href="#actions-action-run">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
run
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-primary?" href="#actions-action-primary?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not this action should be used when no action is specified by the caller.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-description" href="#actions-action-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-transaction?" href="#actions-action-transaction?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
transaction?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-touches_resources" href="#actions-action-touches_resources">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
touches_resources
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of resources that the action may touch, used when building transactions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## actions.action.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
Declares an argument on the action
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :password_confirmation, :string
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-name" href="#actions-action-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-type" href="#actions-action-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-description" href="#actions-action-argument-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the argument.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-constraints" href="#actions-action-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-allow_nil?" href="#actions-action-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-private?" href="#actions-action-argument-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument should be suppliable by the client.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-sensitive?" href="#actions-action-argument-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-action-argument-default" href="#actions-action-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Argument`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Action`
|
|
|
|
## actions.create
|
|
```elixir
|
|
create name
|
|
```
|
|
|
|
|
|
Declares a `create` action. For calling this action, see the `Ash.Api` documentation.
|
|
|
|
|
|
### Nested DSLs
|
|
* [change](#actions-create-change)
|
|
* [validate](#actions-create-validate)
|
|
* [argument](#actions-create-argument)
|
|
* [metadata](#actions-create-metadata)
|
|
|
|
|
|
### Examples
|
|
```
|
|
create :register do
|
|
primary? true
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-name" href="#actions-create-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-allow_nil_input" href="#actions-create-allow_nil_input">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil_input
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes that would normally be required, but should not be for this action. They will still be validated just before the record is created.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-manual" href="#actions-create-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Override the creation behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-upsert?" href="#actions-create-upsert?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
upsert?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Forces all uses of this action to be treated as an upsert.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-upsert_identity" href="#actions-create-upsert_identity">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
upsert_identity
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The identity to use for the upsert. Cannot be overriden by the caller. Ignored if `upsert?` is not set to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-upsert_fields" href="#actions-create-upsert_fields">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
upsert_fields
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:replace_all | {:replace, atom | list(atom)} | {:replace_all_except, atom | list(atom)} | atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The fields to overwrite in the case of an upsert. If not provided, all fields except for fields set by defaults will be overwritten.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-primary?" href="#actions-create-primary?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not this action should be used when no action is specified by the caller.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-description" href="#actions-create-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-transaction?" href="#actions-create-transaction?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
transaction?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-touches_resources" href="#actions-create-touches_resources">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
touches_resources
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of resources that the action may touch, used when building transactions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-accept" href="#actions-create-accept">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
accept
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The list of attributes to accept. Defaults to all attributes on the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-delay_global_validations?" href="#actions-create-delay_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
delay_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-skip_global_validations?" href="#actions-create-skip_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
skip_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be skipped. Useful for manual actions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-reject" href="#actions-create-reject">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
reject
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-require_attributes" href="#actions-create-require_attributes">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
require_attributes
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil?
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-error_handler" href="#actions-create-error_handler">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
error_handler
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">mfa</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-manual?" href="#actions-create-manual?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## actions.create.change
|
|
```elixir
|
|
change change
|
|
```
|
|
|
|
|
|
A change to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
change relate_actor(:reporter)
|
|
```
|
|
|
|
```
|
|
change {MyCustomChange, :foo}
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-change-change" href="#actions-create-change-change">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
change
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-change-only_when_valid?" href="#actions-create-change-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-change-description" href="#actions-create-change-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the change
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-change-where" href="#actions-create-change-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-change-always_atomic?" href="#actions-create-change-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, changes are only run atomically if all changes will be run atomically or if there is no `change/3` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Change`
|
|
|
|
## actions.create.validate
|
|
```elixir
|
|
validate validation
|
|
```
|
|
|
|
|
|
Declares a validation to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Validation` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
validate changing(:email)
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-validation" href="#actions-create-validate-validation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-where" href="#actions-create-validate-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module | list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-only_when_valid?" href="#actions-create-validate-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-message" href="#actions-create-validate-message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If provided, overrides any message set by the validation error
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-description" href="#actions-create-validate-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the validation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-before_action?" href="#actions-create-validate-before_action?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
before_action?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `true`, the validation will be run in a before_action hook
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-validate-always_atomic?" href="#actions-create-validate-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, validations are only run atomically if all changes will be run atomically or if there is no `validate/2` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Validation`
|
|
|
|
## actions.create.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
Declares an argument on the action
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :password_confirmation, :string
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-name" href="#actions-create-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-type" href="#actions-create-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-description" href="#actions-create-argument-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the argument.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-constraints" href="#actions-create-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-allow_nil?" href="#actions-create-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-private?" href="#actions-create-argument-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument should be suppliable by the client.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-sensitive?" href="#actions-create-argument-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-argument-default" href="#actions-create-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Argument`
|
|
|
|
## actions.create.metadata
|
|
```elixir
|
|
metadata name, type
|
|
```
|
|
|
|
|
|
A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom
|
|
change via `Ash.Resource.Info.put_metadata/3`.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
metadata :api_token, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
```
|
|
metadata :operation_id, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-name" href="#actions-create-metadata-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-type" href="#actions-create-metadata-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the metadata. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-constraints" href="#actions-create-metadata-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Type constraints on the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-description" href="#actions-create-metadata-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the metadata.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-allow_nil?" href="#actions-create-metadata-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the metadata may return `nil`
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-create-metadata-default" href="#actions-create-metadata-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Metadata`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Create`
|
|
|
|
## actions.read
|
|
```elixir
|
|
read name
|
|
```
|
|
|
|
|
|
Declares a `read` action. For calling this action, see the `Ash.Api` documentation.
|
|
|
|
|
|
### Nested DSLs
|
|
* [argument](#actions-read-argument)
|
|
* [prepare](#actions-read-prepare)
|
|
* [pagination](#actions-read-pagination)
|
|
* [metadata](#actions-read-metadata)
|
|
|
|
|
|
### Examples
|
|
```
|
|
read :read_all do
|
|
primary? true
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-name" href="#actions-read-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-filter" href="#actions-read-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter template that will be applied whenever the action is used. See `Ash.Filter` for more on templates
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-manual" href="#actions-read-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Delegates running of the query to the provided module. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-get?" href="#actions-read-get?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
get?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Expresses that this action innately only returns a single result. Used by extensions to validate and/or modify behavior. Causes code interfaces to return a single value instead of a list. See the [code interface guide](/documentation/topics/code-interface.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-modify_query" href="#actions-read-modify_query">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
modify_query
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">mfa | (any, any -> any)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Allows direct manipulation of the data layer query via an MFA. The ash query and the data layer query will be provided as additional arguments. The result must be `{:ok, new_data_layer_query} | {:error, error}`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-get_by" href="#actions-read-get_by">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
get_by
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A helper to automatically generate a "get by X" action. Sets `get?` to true, add args for each of the specified fields, and adds a filter for each of the arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-primary?" href="#actions-read-primary?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not this action should be used when no action is specified by the caller.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-description" href="#actions-read-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-transaction?" href="#actions-read-transaction?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
transaction?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-touches_resources" href="#actions-read-touches_resources">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
touches_resources
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of resources that the action may touch, used when building transactions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## actions.read.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
Declares an argument on the action
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :password_confirmation, :string
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-name" href="#actions-read-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-type" href="#actions-read-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-description" href="#actions-read-argument-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the argument.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-constraints" href="#actions-read-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-allow_nil?" href="#actions-read-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-private?" href="#actions-read-argument-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument should be suppliable by the client.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-sensitive?" href="#actions-read-argument-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-argument-default" href="#actions-read-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Argument`
|
|
|
|
## actions.read.prepare
|
|
```elixir
|
|
prepare preparation
|
|
```
|
|
|
|
|
|
Declares a preparation, which can be used to prepare a query for a read action.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
prepare build(sort: [:foo, :bar])
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-prepare-preparation" href="#actions-read-prepare-preparation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
preparation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a preparation. Also accepts functions take the query and the context.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Preparation`
|
|
|
|
## actions.read.pagination
|
|
|
|
|
|
Adds pagination options to a resource
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-keyset?" href="#actions-read-pagination-keyset?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
keyset?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not keyset based pagination is supported
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-offset?" href="#actions-read-pagination-offset?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
offset?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not offset based pagination is supported
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-default_limit" href="#actions-read-pagination-default_limit">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default_limit
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">pos_integer</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default page size to apply, if one is not supplied
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-countable" href="#actions-read-pagination-countable">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
countable
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true | false | :by_default</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether not a returned page will have a full count of all records. Use `:by_default` to do it automatically.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-max_page_size" href="#actions-read-pagination-max_page_size">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
max_page_size
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">pos_integer</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">250</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The maximum amount of records that can be requested in a single page
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-pagination-required?" href="#actions-read-pagination-required?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
required?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not pagination can be disabled. Only relevant if some pagination configuration is supplied.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Read.Pagination`
|
|
|
|
## actions.read.metadata
|
|
```elixir
|
|
metadata name, type
|
|
```
|
|
|
|
|
|
A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom
|
|
change via `Ash.Resource.Info.put_metadata/3`.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
metadata :api_token, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
```
|
|
metadata :operation_id, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-name" href="#actions-read-metadata-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-type" href="#actions-read-metadata-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the metadata. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-constraints" href="#actions-read-metadata-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Type constraints on the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-description" href="#actions-read-metadata-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the metadata.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-allow_nil?" href="#actions-read-metadata-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the metadata may return `nil`
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-read-metadata-default" href="#actions-read-metadata-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Metadata`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Read`
|
|
|
|
## actions.update
|
|
```elixir
|
|
update name
|
|
```
|
|
|
|
|
|
Declares a `update` action. For calling this action, see the `Ash.Api` documentation.
|
|
|
|
|
|
### Nested DSLs
|
|
* [change](#actions-update-change)
|
|
* [validate](#actions-update-validate)
|
|
* [metadata](#actions-update-metadata)
|
|
* [argument](#actions-update-argument)
|
|
|
|
|
|
### Examples
|
|
```
|
|
update :flag_for_review, primary?: true
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-name" href="#actions-update-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-manual" href="#actions-update-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Override the update behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-primary?" href="#actions-update-primary?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not this action should be used when no action is specified by the caller.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-description" href="#actions-update-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-transaction?" href="#actions-update-transaction?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
transaction?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-touches_resources" href="#actions-update-touches_resources">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
touches_resources
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of resources that the action may touch, used when building transactions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-accept" href="#actions-update-accept">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
accept
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The list of attributes to accept. Defaults to all attributes on the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-delay_global_validations?" href="#actions-update-delay_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
delay_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-skip_global_validations?" href="#actions-update-skip_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
skip_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be skipped. Useful for manual actions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-reject" href="#actions-update-reject">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
reject
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-require_attributes" href="#actions-update-require_attributes">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
require_attributes
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil?
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-error_handler" href="#actions-update-error_handler">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
error_handler
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">mfa</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-manual?" href="#actions-update-manual?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## actions.update.change
|
|
```elixir
|
|
change change
|
|
```
|
|
|
|
|
|
A change to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
change relate_actor(:reporter)
|
|
```
|
|
|
|
```
|
|
change {MyCustomChange, :foo}
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-change-change" href="#actions-update-change-change">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
change
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-change-only_when_valid?" href="#actions-update-change-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-change-description" href="#actions-update-change-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the change
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-change-where" href="#actions-update-change-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-change-always_atomic?" href="#actions-update-change-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, changes are only run atomically if all changes will be run atomically or if there is no `change/3` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Change`
|
|
|
|
## actions.update.validate
|
|
```elixir
|
|
validate validation
|
|
```
|
|
|
|
|
|
Declares a validation to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Validation` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
validate changing(:email)
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-validation" href="#actions-update-validate-validation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-where" href="#actions-update-validate-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module | list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-only_when_valid?" href="#actions-update-validate-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-message" href="#actions-update-validate-message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If provided, overrides any message set by the validation error
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-description" href="#actions-update-validate-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the validation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-before_action?" href="#actions-update-validate-before_action?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
before_action?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `true`, the validation will be run in a before_action hook
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-validate-always_atomic?" href="#actions-update-validate-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, validations are only run atomically if all changes will be run atomically or if there is no `validate/2` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Validation`
|
|
|
|
## actions.update.metadata
|
|
```elixir
|
|
metadata name, type
|
|
```
|
|
|
|
|
|
A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom
|
|
change via `Ash.Resource.Info.put_metadata/3`.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
metadata :api_token, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
```
|
|
metadata :operation_id, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-name" href="#actions-update-metadata-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-type" href="#actions-update-metadata-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the metadata. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-constraints" href="#actions-update-metadata-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Type constraints on the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-description" href="#actions-update-metadata-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the metadata.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-allow_nil?" href="#actions-update-metadata-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the metadata may return `nil`
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-metadata-default" href="#actions-update-metadata-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Metadata`
|
|
|
|
## actions.update.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
Declares an argument on the action
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :password_confirmation, :string
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-name" href="#actions-update-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-type" href="#actions-update-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-description" href="#actions-update-argument-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the argument.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-constraints" href="#actions-update-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-allow_nil?" href="#actions-update-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-private?" href="#actions-update-argument-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument should be suppliable by the client.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-sensitive?" href="#actions-update-argument-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-update-argument-default" href="#actions-update-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Argument`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Update`
|
|
|
|
## actions.destroy
|
|
```elixir
|
|
destroy name
|
|
```
|
|
|
|
|
|
Declares a `destroy` action. For calling this action, see the `Ash.Api` documentation.
|
|
|
|
|
|
### Nested DSLs
|
|
* [change](#actions-destroy-change)
|
|
* [validate](#actions-destroy-validate)
|
|
* [metadata](#actions-destroy-metadata)
|
|
* [argument](#actions-destroy-argument)
|
|
|
|
|
|
### Examples
|
|
```
|
|
destroy :soft_delete do
|
|
primary? true
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-name" href="#actions-destroy-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-soft?" href="#actions-destroy-soft?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
soft?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If specified, the destroy action behaves as an update internally
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-manual" href="#actions-destroy-manual">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Override the update behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-primary?" href="#actions-destroy-primary?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
primary?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not this action should be used when no action is specified by the caller.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-description" href="#actions-destroy-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the action
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-transaction?" href="#actions-destroy-transaction?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
transaction?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-touches_resources" href="#actions-destroy-touches_resources">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
touches_resources
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of resources that the action may touch, used when building transactions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-accept" href="#actions-destroy-accept">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
accept
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The list of attributes to accept. Defaults to all attributes on the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-delay_global_validations?" href="#actions-destroy-delay_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
delay_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-skip_global_validations?" href="#actions-destroy-skip_global_validations?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
skip_global_validations?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If true, global validations will be skipped. Useful for manual actions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-reject" href="#actions-destroy-reject">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
reject
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:all | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-require_attributes" href="#actions-destroy-require_attributes">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
require_attributes
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil?
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-error_handler" href="#actions-destroy-error_handler">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
error_handler
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">mfa</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-manual?" href="#actions-destroy-manual?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
manual?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## actions.destroy.change
|
|
```elixir
|
|
change change
|
|
```
|
|
|
|
|
|
A change to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
change relate_actor(:reporter)
|
|
```
|
|
|
|
```
|
|
change {MyCustomChange, :foo}
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-change-change" href="#actions-destroy-change-change">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
change
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-change-only_when_valid?" href="#actions-destroy-change-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-change-description" href="#actions-destroy-change-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the change
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-change-where" href="#actions-destroy-change-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-change-always_atomic?" href="#actions-destroy-change-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, changes are only run atomically if all changes will be run atomically or if there is no `change/3` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Change`
|
|
|
|
## actions.destroy.validate
|
|
```elixir
|
|
validate validation
|
|
```
|
|
|
|
|
|
Declares a validation to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Validation` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
validate changing(:email)
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-validation" href="#actions-destroy-validate-validation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-where" href="#actions-destroy-validate-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module | list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-only_when_valid?" href="#actions-destroy-validate-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-message" href="#actions-destroy-validate-message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If provided, overrides any message set by the validation error
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-description" href="#actions-destroy-validate-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the validation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-before_action?" href="#actions-destroy-validate-before_action?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
before_action?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `true`, the validation will be run in a before_action hook
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-validate-always_atomic?" href="#actions-destroy-validate-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, validations are only run atomically if all changes will be run atomically or if there is no `validate/2` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Validation`
|
|
|
|
## actions.destroy.metadata
|
|
```elixir
|
|
metadata name, type
|
|
```
|
|
|
|
|
|
A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom
|
|
change via `Ash.Resource.Info.put_metadata/3`.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
metadata :api_token, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
```
|
|
metadata :operation_id, :string, allow_nil?: false
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-name" href="#actions-destroy-metadata-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-type" href="#actions-destroy-metadata-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the metadata. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-constraints" href="#actions-destroy-metadata-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Type constraints on the metadata
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-description" href="#actions-destroy-metadata-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the metadata.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-allow_nil?" href="#actions-destroy-metadata-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the metadata may return `nil`
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-metadata-default" href="#actions-destroy-metadata-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Metadata`
|
|
|
|
## actions.destroy.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
Declares an argument on the action
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :password_confirmation, :string
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-name" href="#actions-destroy-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-type" href="#actions-destroy-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-description" href="#actions-destroy-argument-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the argument.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-constraints" href="#actions-destroy-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md).
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-allow_nil?" href="#actions-destroy-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-private?" href="#actions-destroy-argument-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument should be suppliable by the client.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-sensitive?" href="#actions-destroy-argument-sensitive?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sensitive?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="actions-destroy-argument-default" href="#actions-destroy-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Argument`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Actions.Destroy`
|
|
|
|
|
|
|
|
|
|
## code_interface
|
|
Functions that will be defined on the Api module to interact with this resource. See the [code interface guide](/documentation/topics/code-interface.md) for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [define](#code_interface-define)
|
|
* [define_calculation](#code_interface-define_calculation)
|
|
|
|
|
|
### Examples
|
|
```
|
|
code_interface do
|
|
define_for MyApp.Api
|
|
define :create_user, action: :create
|
|
define :get_user_by_id, action: :get_by_id, args: [:id], get?: true
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define_for" href="#code_interface-define_for">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
define_for
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Defines the code interface on the resource module directly, using the provided Api.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
## code_interface.define
|
|
```elixir
|
|
define name
|
|
```
|
|
|
|
|
|
Defines a function with the corresponding name and arguments. See the [code interface guide](/documentation/topics/code-interface.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
define :get_user_by_id, action: :get_by_id, args: [:id], get?: true
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-name" href="#code_interface-define-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the function that will be defined
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-action" href="#code_interface-define-action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the action that will be called. Defaults to the same name as the function.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-args" href="#code_interface-define-args">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
args
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom | {:optional, atom})</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Map specific arguments to named inputs. Can provide any argument/attributes that the action allows.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-not_found_error?" href="#code_interface-define-not_found_error?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
not_found_error?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the action or interface is configured with `get?: true`, this determines whether or not an error is raised or `nil` is returned.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-get?" href="#code_interface-define-get?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
get?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Expects to only receive a single result from a read action, and returns a single result instead of a list. Ignored for other action types.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-get_by" href="#code_interface-define-get_by">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
get_by
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Takes a list of fields and adds those fields as arguments, which will then be used to filter. Sets `get?` to true automatically. Ignored for non-read actions.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define-get_by_identity" href="#code_interface-define-get_by_identity">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
get_by_identity
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Only relevant for read actions. Takes an identity, and gets its field list, performing the same logic as `get_by` once it has the list of fields.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Interface`
|
|
|
|
## code_interface.define_calculation
|
|
```elixir
|
|
define_calculation name
|
|
```
|
|
|
|
|
|
Defines a function with the corresponding name and arguments, that evaluates a calculation. Use `:_record` to take an instance of a record. See the [code interface guide](/documentation/topics/code-interface.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
define_calculation :referral_link, args: [:id]
|
|
```
|
|
|
|
```
|
|
define_calculation :referral_link, args: [{:arg, :id}, {:ref, :id}]
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define_calculation-name" href="#code_interface-define_calculation-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the function that will be defined
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define_calculation-calculation" href="#code_interface-define_calculation-calculation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
calculation
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the calculation that will be evaluated. Defaults to the same name as the function.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="code_interface-define_calculation-args" href="#code_interface-define_calculation-args">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
args
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Supply field or argument values referenced by the calculation, in the form of :name, `{:arg, :name}` and/or `{:ref, :name}`. See the [code interface guide](/documentation/topics/code-interface.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.CalculationInterface`
|
|
|
|
|
|
|
|
|
|
## resource
|
|
General resource configuration
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
resource do
|
|
description "A description of this resource"
|
|
base_filter [is_nil: :deleted_at]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-description" href="#resource-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A human readable description of the resource, to be used in generated documentation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-base_filter" href="#resource-base_filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
base_filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter statement to be applied to any queries on the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-default_context" href="#resource-default_context">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default_context
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Default context to apply to any queries/changesets generated for this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-trace_name" href="#resource-trace_name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
trace_name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name to use in traces. Defaults to the short_name stringified. See the [monitoring guide](/documentation/topics/monitoring.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-short_name" href="#resource-short_name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
short_name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A short identifier for the resource, which should be unique. See the [monitoring guide](/documentation/topics/monitoring.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-plural_name" href="#resource-plural_name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
plural_name
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A pluralized version of the resource short_name. May be used by generators or automated tooling.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-simple_notifiers" href="#resource-simple_notifiers">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
simple_notifiers
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of notifiers that require no DSL. Can be used to avoid compile time dependencies on notifiers
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="resource-require_primary_key?" href="#resource-require_primary_key?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
require_primary_key?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Allow the resource to be used without any primary key fields. Warning: this option is experimental, and should not be used unless you know what you're doing.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## identities
|
|
Unique identifiers for the resource
|
|
|
|
|
|
### Nested DSLs
|
|
* [identity](#identities-identity)
|
|
|
|
|
|
### Examples
|
|
```
|
|
identities do
|
|
identity :full_name, [:first_name, :last_name]
|
|
identity :email, [:email]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## identities.identity
|
|
```elixir
|
|
identity name, keys
|
|
```
|
|
|
|
|
|
Represents a unique constraint on the resource.
|
|
|
|
See the [identities guide](/documentation/topics/identities.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
identity :name, [:name]
|
|
```
|
|
|
|
```
|
|
identity :full_name, [:first_name, :last_name]
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-name" href="#identities-identity-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the identity.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-keys" href="#identities-identity-keys">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
keys
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The names of the attributes that uniquely identify this resource.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-eager_check_with" href="#identities-identity-eager_check_with">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
eager_check_with
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validates that the unique identity provided is unique at validation time, outside of any transactions, using the api module provided.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-pre_check_with" href="#identities-identity-pre_check_with">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
pre_check_with
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validates that the unique identity provided is unique in a before_action hook.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-description" href="#identities-identity-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the identity
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="identities-identity-message" href="#identities-identity-message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An error message to use when the unique identity would be violated
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Identity`
|
|
|
|
|
|
|
|
|
|
## changes
|
|
Declare changes that occur on create/update/destroy actions against the resource
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [change](#changes-change)
|
|
|
|
|
|
### Examples
|
|
```
|
|
changes do
|
|
change {Mod, [foo: :bar]}
|
|
change set_context(%{some: :context})
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## changes.change
|
|
```elixir
|
|
change change
|
|
```
|
|
|
|
|
|
A change to be applied to the changeset.
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
change relate_actor(:reporter)
|
|
```
|
|
|
|
```
|
|
change {MyCustomChange, :foo}
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-change" href="#changes-change-change">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
change
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-on" href="#changes-change-on">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
on
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:create | :update | :destroy | list(:create | :update | :destroy)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[:create, :update]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The action types the validation should run on. Destroy actions are omitted by default as most changes don't make sense for a destroy.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-only_when_valid?" href="#changes-change-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-description" href="#changes-change-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the change
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-where" href="#changes-change-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="changes-change-always_atomic?" href="#changes-change-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, changes are only run atomically if all changes will be run atomically or if there is no `change/3` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Change`
|
|
|
|
|
|
|
|
|
|
## preparations
|
|
Declare preparations that occur on all read actions for a given resource
|
|
|
|
|
|
### Nested DSLs
|
|
* [prepare](#preparations-prepare)
|
|
|
|
|
|
### Examples
|
|
```
|
|
preparations do
|
|
prepare {Mod, [foo: :bar]}
|
|
prepare set_context(%{some: :context})
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## preparations.prepare
|
|
```elixir
|
|
prepare preparation
|
|
```
|
|
|
|
|
|
Declares a preparation, which can be used to prepare a query for a read action.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
prepare build(sort: [:foo, :bar])
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="preparations-prepare-preparation" href="#preparations-prepare-preparation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
preparation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module and options for a preparation. Also accepts functions take the query and the context.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Preparation`
|
|
|
|
|
|
|
|
|
|
## validations
|
|
Declare validations prior to performing actions against the resource
|
|
|
|
|
|
### Nested DSLs
|
|
* [validate](#validations-validate)
|
|
|
|
|
|
### Examples
|
|
```
|
|
validations do
|
|
validate {Mod, [foo: :bar]}
|
|
validate at_least_one_of_present([:first_name, :last_name])
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## validations.validate
|
|
```elixir
|
|
validate validation
|
|
```
|
|
|
|
|
|
Declares a validation for creates and updates.
|
|
|
|
See `Ash.Resource.Change` for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
validate {Mod, [foo: :bar]}
|
|
```
|
|
|
|
```
|
|
validate at_least_one_of_present([:first_name, :last_name])
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-validation" href="#validations-validate-validation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
validation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-where" href="#validations-validate-where">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
where
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any -> any) | module | list((any -> any) | module)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-on" href="#validations-validate-on">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
on
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:create | :update | :destroy | list(:create | :update | :destroy)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[:create, :update]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The action types the validation should run on. Many validations don't make sense in the context of deletion, so by default it is not included.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-only_when_valid?" href="#validations-validate-only_when_valid?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
only_when_valid?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-message" href="#validations-validate-message">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
message
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If provided, overrides any message set by the validation error
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-description" href="#validations-validate-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the validation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-before_action?" href="#validations-validate-before_action?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
before_action?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If set to `true`, the validation will be run in a before_action hook
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="validations-validate-always_atomic?" href="#validations-validate-always_atomic?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
always_atomic?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
By default, validations are only run atomically if all changes will be run atomically or if there is no `validate/2` callback defined. Set this to `true` to run it atomically always.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Validation`
|
|
|
|
|
|
|
|
|
|
## aggregates
|
|
Declare named aggregates on the resource.
|
|
|
|
These are aggregates that can be loaded only by name using `Ash.Query.load/2`.
|
|
They are also available as top level fields on the resource.
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [count](#aggregates-count)
|
|
* [exists](#aggregates-exists)
|
|
* [first](#aggregates-first)
|
|
* [sum](#aggregates-sum)
|
|
* [list](#aggregates-list)
|
|
* [max](#aggregates-max)
|
|
* [min](#aggregates-min)
|
|
* [avg](#aggregates-avg)
|
|
* [custom](#aggregates-custom)
|
|
|
|
|
|
### Examples
|
|
```
|
|
aggregates do
|
|
count :assigned_ticket_count, :reported_tickets do
|
|
filter [active: true]
|
|
end
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## aggregates.count
|
|
```elixir
|
|
count name, relationship_path
|
|
```
|
|
|
|
|
|
Declares a named count aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect the count)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
count :assigned_ticket_count, :assigned_tickets do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-name" href="#aggregates-count-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-relationship_path" href="#aggregates-count-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-kind" href="#aggregates-count-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-uniq?" href="#aggregates-count-uniq?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
uniq?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to count unique values only
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-read_action" href="#aggregates-count-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-field" href="#aggregates-count-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-filter" href="#aggregates-count-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-description" href="#aggregates-count-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-default" href="#aggregates-count-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-private?" href="#aggregates-count-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-filterable?" href="#aggregates-count-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-count-authorize?" href="#aggregates-count-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.exists
|
|
```elixir
|
|
exists name, relationship_path
|
|
```
|
|
|
|
|
|
Declares a named `exists` aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect if something exists)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
exists :has_ticket, :assigned_tickets
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-name" href="#aggregates-exists-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-relationship_path" href="#aggregates-exists-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-kind" href="#aggregates-exists-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-read_action" href="#aggregates-exists-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-filter" href="#aggregates-exists-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-description" href="#aggregates-exists-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-default" href="#aggregates-exists-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-private?" href="#aggregates-exists-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-filterable?" href="#aggregates-exists-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-exists-authorize?" href="#aggregates-exists-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.first
|
|
```elixir
|
|
first name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `first` aggregate on the resource
|
|
|
|
First aggregates return the first value of the related record
|
|
that matches. Supports both `filter` and `sort`.
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
first :first_assigned_ticket_subject, :assigned_tickets, :subject do
|
|
filter [active: true]
|
|
sort [:subject]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-name" href="#aggregates-first-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-relationship_path" href="#aggregates-first-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-field" href="#aggregates-first-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-kind" href="#aggregates-first-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-read_action" href="#aggregates-first-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-filter" href="#aggregates-first-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-sort" href="#aggregates-first-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort to be applied to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-description" href="#aggregates-first-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-default" href="#aggregates-first-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-private?" href="#aggregates-first-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-filterable?" href="#aggregates-first-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-first-authorize?" href="#aggregates-first-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.sum
|
|
```elixir
|
|
sum name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `sum` aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect the sum)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
sum :assigned_ticket_price_sum, :assigned_tickets, :price do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-name" href="#aggregates-sum-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-relationship_path" href="#aggregates-sum-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-field" href="#aggregates-sum-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-kind" href="#aggregates-sum-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-read_action" href="#aggregates-sum-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-filter" href="#aggregates-sum-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-description" href="#aggregates-sum-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-default" href="#aggregates-sum-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-private?" href="#aggregates-sum-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-filterable?" href="#aggregates-sum-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-sum-authorize?" href="#aggregates-sum-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.list
|
|
```elixir
|
|
list name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `list` aggregate on the resource.
|
|
|
|
A list aggregate selects the list of all values for the given field
|
|
and relationship combination.
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
list :assigned_ticket_prices, :assigned_tickets, :price do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-name" href="#aggregates-list-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-relationship_path" href="#aggregates-list-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-field" href="#aggregates-list-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-kind" href="#aggregates-list-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-uniq?" href="#aggregates-list-uniq?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
uniq?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not to count unique values only
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-read_action" href="#aggregates-list-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-filter" href="#aggregates-list-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-sort" href="#aggregates-list-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort to be applied to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-description" href="#aggregates-list-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-default" href="#aggregates-list-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-private?" href="#aggregates-list-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-filterable?" href="#aggregates-list-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-list-authorize?" href="#aggregates-list-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.max
|
|
```elixir
|
|
max name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `max` aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect the max)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
max :first_assigned_ticket_subject, :assigned_tickets, :severity do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-name" href="#aggregates-max-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-relationship_path" href="#aggregates-max-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-field" href="#aggregates-max-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-kind" href="#aggregates-max-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-read_action" href="#aggregates-max-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-filter" href="#aggregates-max-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-description" href="#aggregates-max-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-default" href="#aggregates-max-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-private?" href="#aggregates-max-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-filterable?" href="#aggregates-max-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-max-authorize?" href="#aggregates-max-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.min
|
|
```elixir
|
|
min name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `min` aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect the min)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
min :first_assigned_ticket_subject, :assigned_tickets, :severity do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-name" href="#aggregates-min-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-relationship_path" href="#aggregates-min-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-field" href="#aggregates-min-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-kind" href="#aggregates-min-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-read_action" href="#aggregates-min-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-filter" href="#aggregates-min-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-description" href="#aggregates-min-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-default" href="#aggregates-min-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-private?" href="#aggregates-min-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-filterable?" href="#aggregates-min-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-min-authorize?" href="#aggregates-min-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.avg
|
|
```elixir
|
|
avg name, relationship_path, field
|
|
```
|
|
|
|
|
|
Declares a named `avg` aggregate on the resource
|
|
|
|
Supports `filter`, but not `sort` (because that wouldn't affect the avg)
|
|
|
|
See the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
avg :assigned_ticket_price_sum, :assigned_tickets, :price do
|
|
filter [active: true]
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-name" href="#aggregates-avg-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-relationship_path" href="#aggregates-avg-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-field" href="#aggregates-avg-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-kind" href="#aggregates-avg-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-read_action" href="#aggregates-avg-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-filter" href="#aggregates-avg-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-description" href="#aggregates-avg-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-default" href="#aggregates-avg-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-private?" href="#aggregates-avg-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-filterable?" href="#aggregates-avg-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-avg-authorize?" href="#aggregates-avg-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
## aggregates.custom
|
|
```elixir
|
|
custom name, relationship_path, type
|
|
```
|
|
|
|
|
|
Declares a named `custom` aggregate on the resource
|
|
|
|
Supports `filter` and `sort`.
|
|
|
|
Custom aggregates provide an `implementation` which must implement data layer specific callbacks.
|
|
|
|
See the relevant data layer documentation and the [aggregates guide](/documentation/topics/aggregates.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
custom :author_names, :authors, :string do
|
|
implementation {StringAgg, delimiter: ","}
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-name" href="#aggregates-custom-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to place the aggregate in
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-relationship_path" href="#aggregates-custom-relationship_path">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
relationship_path
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom | list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The relationship or relationship path to use for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-type" href="#aggregates-custom-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the value returned by the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-implementation" href="#aggregates-custom-implementation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
implementation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The module that implements the relevant data layer callbacks
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-kind" href="#aggregates-custom-kind">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
kind
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:count | :first | :sum | :list | :avg | :max | :min | :exists | :custom | {:custom, module}</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The kind of the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-read_action" href="#aggregates-custom-read_action">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
read_action
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-field" href="#aggregates-custom-field">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
field
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field to aggregate. Defaults to the first field in the primary key of the resource
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-filter" href="#aggregates-custom-filter">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filter
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A filter to apply to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-sort" href="#aggregates-custom-sort">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
sort
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A sort to be applied to the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-description" href="#aggregates-custom-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the aggregate
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-default" href="#aggregates-custom-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use in cases where nil would be used. Count defaults to `0`.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-private?" href="#aggregates-custom-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-filterable?" href="#aggregates-custom-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="aggregates-custom-authorize?" href="#aggregates-custom-authorize?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
authorize?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Aggregate`
|
|
|
|
|
|
|
|
|
|
## calculations
|
|
Declare named calculations on the resource.
|
|
|
|
These are calculations that can be loaded only by name using `Ash.Query.load/2`.
|
|
They are also available as top level fields on the resource.
|
|
|
|
See the [calculations guide](/documentation/topics/calculations.md) for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [calculate](#calculations-calculate)
|
|
* argument
|
|
|
|
|
|
### Examples
|
|
```
|
|
calculations do
|
|
calculate :full_name, :string, MyApp.MyResource.FullName
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## calculations.calculate
|
|
```elixir
|
|
calculate name, type, calculation \ nil
|
|
```
|
|
|
|
|
|
Declares a named calculation on the resource.
|
|
|
|
Takes a module that must adopt the `Ash.Calculation` behaviour. See that module
|
|
for more information.
|
|
|
|
To ensure that the necessary fields are selected:
|
|
|
|
1.) Specifying the `select` option on a calculation in the resource.
|
|
2.) Define a `select/2` callback in the calculation module
|
|
3.) Set `always_select?` on the attribute in question
|
|
|
|
See the [calculations guide](/documentation/topics/calculations.md) for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [argument](#calculations-calculate-argument)
|
|
|
|
|
|
### Examples
|
|
`Ash.Calculation` implementation example:
|
|
```
|
|
calculate :full_name, :string, {MyApp.FullName, keys: [:first_name, :last_name]}, select: [:first_name, :last_name]
|
|
```
|
|
|
|
`expr/1` example:
|
|
```
|
|
calculate :full_name, :string, expr(first_name <> " " <> last_name)
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-name" href="#calculations-calculate-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The field name to use for the calculation value
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-type" href="#calculations-calculate-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the calculation. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-calculation" href="#calculations-calculate-calculation">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
calculation
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(any, any -> any) | module | `any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The `module`, `{module, opts}` or `expr(...)` to use for the calculation. Also accepts a function that takes *a single record* and produces the result.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-constraints" href="#calculations-calculate-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-description" href="#calculations-calculate-description">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
description
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">String.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An optional description for the calculation
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-private?" href="#calculations-calculate-private?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
private?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the calculation will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-select" href="#calculations-calculate-select">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
select
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">list(atom)</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A list of fields to ensure selected if the calculation is used.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-load" href="#calculations-calculate-load">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
load
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">`any`</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A load statement to be applied if the calculation is used.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-allow_nil?" href="#calculations-calculate-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the calculation can return nil.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-filterable?" href="#calculations-calculate-filterable?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
filterable?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean | :simple_equality</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the calculation should be usable in filters.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
## calculations.calculate.argument
|
|
```elixir
|
|
argument name, type
|
|
```
|
|
|
|
|
|
An argument to be passed into the calculation's arguments map
|
|
|
|
See the [calculations guide](/documentation/topics/calculations.md) for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
argument :params, :map do
|
|
default %{}
|
|
end
|
|
|
|
```
|
|
|
|
```
|
|
argument :retries, :integer do
|
|
allow_nil? false
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-name" href="#calculations-calculate-argument-name">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
name
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The name of the argument
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-type" href="#calculations-calculate-argument-type">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
type
|
|
</span>
|
|
</a>
|
|
<sup style="color: red">*</sup>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">module</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
The type of the argument. See `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-default" href="#calculations-calculate-argument-default">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
default
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">(-> any) | mfa | any()</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
A default value to use for the argument if not provided
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-allow_nil?" href="#calculations-calculate-argument-allow_nil?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_nil?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">true</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the argument value may be nil (or may be not provided)
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-allow_expr?" href="#calculations-calculate-argument-allow_expr?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
allow_expr?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Allow passing expressions as argument values. Expressions cannot be type validated.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="calculations-calculate-argument-constraints" href="#calculations-calculate-argument-constraints">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
constraints
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">Keyword.t</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">[]</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Constraints to provide to the type when casting the value. See the type's documentation and `Ash.Type` for more.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Calculation.Argument`
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Resource.Calculation`
|
|
|
|
|
|
|
|
|
|
## multitenancy
|
|
Options for configuring the multitenancy behavior of a resource.
|
|
|
|
To specify a tenant, use `Ash.Query.set_tenant/2` or
|
|
`Ash.Changeset.set_tenant/2` before passing it to an operation.
|
|
|
|
See the [multitenancy guide](/documentation/topics/multitenancy.md)
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
multitenancy do
|
|
strategy :attribute
|
|
attribute :organization_id
|
|
global? true
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th colspan=2>Docs</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="multitenancy-strategy" href="#multitenancy-strategy">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
strategy
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:context | :attribute</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">:context</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Determine if multitenancy is performed with attribute filters or using data layer features.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="multitenancy-attribute" href="#multitenancy-attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">atom</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
If using the `attribute` strategy, the attribute to use, e.g `org_id`
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="multitenancy-global?" href="#multitenancy-global?">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
global?
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">boolean</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">false</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
Whether or not the data also exists outside of each tenant.
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="text-align: left">
|
|
<a id="multitenancy-parse_attribute" href="#multitenancy-parse_attribute">
|
|
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
|
|
parse_attribute
|
|
</span>
|
|
</a>
|
|
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">mfa</code>
|
|
</td>
|
|
<td style="text-align: left">
|
|
<code class="inline">{Ash.Resource.Dsl, :identity, []}</code>
|
|
</td>
|
|
<td style="text-align: left" colspan=2>
|
|
An mfa ({module, function, args}) pointing to a function that takes a tenant and returns the attribute value
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|