Current section
Files
Jump to
Current section
Files
lib/ash/resource/relationships/has_one.ex
defmodule Ash.Resource.Relationships.HasOne do
@moduledoc "Represents a has_one relationship on a resource"
defstruct [
:name,
:source,
:destination,
:destination_field,
:source_field,
:allow_orphans?,
:writable?,
cardinality: :one,
type: :has_one
]
@type t :: %__MODULE__{
type: :has_one,
cardinality: :one,
source: Ash.resource(),
writable?: boolean,
name: atom,
type: Ash.Type.t(),
destination: Ash.resource(),
destination_field: atom,
source_field: atom,
allow_orphans?: boolean
}
alias Ash.OptionsHelpers
import Ash.Resource.Relationships.SharedOptions
@global_opts shared_options()
|> OptionsHelpers.make_required!(:destination_field)
|> OptionsHelpers.set_default!(:source_field, :id)
@opt_schema Ash.OptionsHelpers.merge_schemas(
[],
@global_opts,
"Relationship Options"
)
@doc false
def opt_schema, do: @opt_schema
end