ash v0.10.0 Ash.Dsl.BelongsTo View Source
Link to this section Summary
Functions
Declares a belongs_to relationship. In a relational database, the foreign key would be on the source table.
Link to this section Functions
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_field?: false
is provided.
Examples
# In a resource called `Word`
belongs_to :dictionary_entry, DictionaryEntry,
source_field: :text,
destination_field: :word_text
Arguments
:name
- The name of the relationship:destination
- The destination resource
Options
:primary_key?
- Whether this field is, or is part of, the primary key of a resource. The default value isfalse
.:define_field?
- If set tofalse
a field is not created on the resource for this relationship, and one must be manually added inattributes
. The default value istrue
.:field_type
- The field type of the automatically created field. The default value is:uuid
.:destination_field
- false The field on the related resource that should match thesource_field
on this resource. The default value is:id
.:source_field
- The field on this resource that should match thedestination_field
on the related resource. - Defaults to <name>_id