ash v0.10.0 Ash.Dsl.HasOne View Source

Link to this section Summary

Functions

Declares a has_one relationship. In a relationsal database, the foreign key would be on the other table.

Link to this section Functions

Link to this macro

has_one(name, destination, opts \\ [])

View Source (macro)

Declares a has_one relationship. In a relationsal 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.

Examples

# In a resource called `Word`
has_one :dictionary_entry, DictionaryEntry,
  source_field: :text,
  destination_field: :word_text

Arguments

  • :name - The name of the relationship

  • :destination - The destination resource

Options

  • :destination_field - Required. The field on the related resource that should match the source_field on this resource.

  • :source_field - false The field on this resource that should match the destination_field on the related resource. The default value is :id.