AncestryEx.Config (ancestry_ex v0.1.0)

Copy Markdown View Source

Compile-time configuration of a schema that uses AncestryEx.

A config is built by use AncestryEx and can be retrieved at runtime with MySchema.__ancestry__/0. See AncestryEx for the list of options.

Summary

Functions

Casts a value (usually a segment of the ancestry string) to the primary key type.

Returns the config of the given schema module or struct.

Builds and validates a config for schema. Raises ArgumentError on invalid options.

Returns the primary key field of the schema. Only single-column keys are supported.

Returns the Ecto type of the primary key.

Types

orphan_strategy()

@type orphan_strategy() :: :destroy | :rootify | :adopt | :restrict | :none

t()

@type t() :: %AncestryEx.Config{
  column: atom(),
  counter_cache_column: atom() | nil,
  depth_column: atom() | nil,
  depth_mode: :stored | :virtual | nil,
  format: AncestryEx.Format.t(),
  orphan_strategy: orphan_strategy(),
  schema: module(),
  touch: boolean()
}

Functions

cast_id(config, value)

@spec cast_id(t(), term()) :: {:ok, term()} | :error

Casts a value (usually a segment of the ancestry string) to the primary key type.

fetch!(schema)

@spec fetch!(module() | struct()) :: t()

Returns the config of the given schema module or struct.

new!(schema, opts)

@spec new!(module(), keyword()) :: t()

Builds and validates a config for schema. Raises ArgumentError on invalid options.

primary_key(config)

@spec primary_key(t()) :: atom()

Returns the primary key field of the schema. Only single-column keys are supported.

primary_key_type(config)

@spec primary_key_type(t()) :: Ecto.Type.t()

Returns the Ecto type of the primary key.