ash v1.10.0 Ash.Resource.Dsl.Attribute View Source

Link to this section Summary

Functions

Declares an attribute on the resource

Link to this section Functions

Link to this macro

attribute(name, type, opts \\ [])

View Source (macro)

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.

Examples

attribute :first_name, :string, primary_key?: true

Arguments

  • :name - The name of the attribute.

  • :type - The type of the attribute.

Options

  • :constraints - Constraints to provide to the type when casting the value. See the type's documentation for more information.

  • :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 is false.

  • :allow_nil? - Whether or not the attribute can be set to nil The default value is true.

  • :generated? - Whether or not the value may be generated by the data layer. If it is, the data layer will know to read the value back after writing. The default value is false.

  • :writable? - Whether or not the value can be written to The default value is true.

  • :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.

  • :description - An optional description for the attribute