ash v1.25.4 Ash.Resource.Dsl View Source
The built in resource DSL. The core DSL components of a resource are:
- attributes -
attributes/1
- relationships -
relationships/1
- actions -
actions/1
- validations -
validations/1
- aggregates -
aggregates/1
- calculations -
calculations/1
Link to this section Summary
Functions
A section for declaring resource actions.
Declare named aggregates on the resource.
A section for declaring attributes on the resource.
Declare named calculations on the resource.
Options for configuring the multitenancy behavior of a resource.
A section for declaring relationships on the resource.
Resource-wide configuration
Declare validations prior to performing actions against the resource
Link to this section Functions
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.
If you have multiple actions of the same type, one of them must be designated as the
primary action for that type, via: primary?: true
. This tells the ash what to do
if an action of that type is requested, but no specific action name is given.
Constructors
- create -
Ash.Resource.Dsl.Create
- read -
Ash.Resource.Dsl.Read
- update -
Ash.Resource.Dsl.Update
- destroy -
Ash.Resource.Dsl.Destroy
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.
Constructors
- count -
Ash.Resource.Dsl.Count
A section for declaring attributes on the resource.
Attributes are fields on an instance of a resource. The two required pieces of knowledge are the field name, and the type.
Constructors
- attribute -
Ash.Resource.Dsl.Attribute
- create_timestamp -
Ash.Resource.Dsl.CreateTimestamp
- update_timestamp -
Ash.Resource.Dsl.UpdateTimestamp
- integer_primary_key -
Ash.Resource.Dsl.IntegerPrimaryKey
- uuid_primary_key -
Ash.Resource.Dsl.UuidPrimaryKey
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.
Constructors
- calculate -
Ash.Resource.Dsl.Calculate
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.
Options
:strategy
- Determine how to perform multitenancy.:attribute
will expect that an attribute matches the giventenant
, e.gorg_id
.context
(the default) implies that the tenant will be passed to the datalayer as context. How a given data layer handles multitenancy will differ depending on the implementation. See the datalayer documentation for more. The default value is:context
.:attribute
- If using theattribute
strategy, the attribute to use, e.gorg_id
:global?
- Whether or not the data also exists outside of each tenant. This allows running queries and making changes without setting a tenant. This may eventually be extended to support describing the relationship to global data. For example, perhaps the global data is shared among all tenants (requiring "union" support in data layers), or perhaps global data is "merged" using some strategy (also requiring "union" support). The default value isfalse
.:parse_attribute
- An mfa ({module, function, args}) pointing to a function that takes a tenant and returns the attribute value The default value is{Ash.Resource.Dsl, :identity, []}
.
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 side_loading (done via the Ash.Query.load/2
).
Constructors
- has_one -
Ash.Resource.Dsl.HasOne
- has_many -
Ash.Resource.Dsl.HasMany
- many_to_many -
Ash.Resource.Dsl.ManyToMany
- belongs_to -
Ash.Resource.Dsl.BelongsTo
Resource-wide configuration
Options
:description
- A human readable description of the resource, to be used in generated documentation:base_filter
- A filter statement to be applied to any queries on the resource
Sections
- identities -
Ash.Resource.Dsl.Identities
Declare validations prior to performing actions against the resource
Constructors
- validate -
Ash.Resource.Dsl.Validate