ash v0.1.8 Ash.Resource.Attributes View Source
A DSL component for declaring attributes
Attributes are fields on an instance of a resource. The two required pieces of knowledge are the field name, and the type.
Link to this section Summary
Link to this section Functions
Declares an attribute on the resource
Type can be either a built in type (see Ash.Type
) for more, or a module
implementing the Ash.Type
behaviour.
:primary_key?
- Whether or not the attribute is part of the primary key (one or more fields that uniquely identify a resource) The default value isfalse
.:allow_nil?
- Whether or not the attribute can be set to nil The default value istrue
.:generated?
- Whether or not the value may be generated by the data layer The default value isfalse
.:writable?
- Whether or not the value can be written to The default value istrue
.:update_default
- A zero argument function, an {mod, fun, args} triple or{:constant, value}
. If no value is provided for the attribute on update, this value is used.:default
- A zero argument function, an {mod, fun, args} triple or{:constant, value}
. If no value is provided for the attribute on create, this value is used.
Examples
attribute :first_name, :string, primary_key?: true
Adds auto updating timestamp fields
The field names default to :inserted_at
and :updated_at
, but can be overwritten via
passing overrides in the opts, e.g timestamps(inserted_at: :created_at, updated_at: :last_touched)
:inserted_at_field
- The name to use for the inserted at field The default value is:inserted_at
.:updated_at_field
- The name to use for the updated at field The default value is:updated_at
.
Examples
attribute :first_name, :string, primary_key?: true