Diffo.Provider.Calculations.FieldViaRelationship (Diffo v0.4.0)

Copy Markdown View Source

Reads a field from target instances reached via DefinedSimpleRelationship.

Traverses DefinedSimpleRelationship in the forward direction — filtering by source_id = current.id — and returns the named field from each resolved target instance. Both type: and alias: are optional filters; when omitted they match any value on that dimension.

Options

  • field: (required) — atom naming the field to read from the target instance (e.g. :name, :type).
  • alias: (optional) — atom matching the alias attribute on the relationship. When omitted, relationships with any alias (including nil) are included.
  • type: (optional) — atom matching the type attribute on the relationship (e.g. :assignedTo, :reliesOn). When omitted, all types are included.

Providing neither filter returns fields from every forward DefinedSimpleRelationship on this instance. In practice at least one of alias: or type: should be supplied, since a source instance typically has many forward relationships pointing to unrelated things.

Examples

# Name of the target reached via the :provides alias
calculate :provider_name, {:array, :string},
  {Diffo.Provider.Calculations.FieldViaRelationship, [alias: :provides, field: :name]}

# Name of the target reached via the :link alias, restricted to :assignedTo type
calculate :assigned_linked_name, {:array, :string},
  {Diffo.Provider.Calculations.FieldViaRelationship,
   [type: :assignedTo, alias: :link, field: :name]}

Summary

Functions

describe(opts)

Callback implementation for Ash.Resource.Calculation.describe/1.

has_calculate?()

has_expression?()

Callback implementation for Ash.Resource.Calculation.has_expression?/0.

init(opts)

Callback implementation for Ash.Resource.Calculation.init/1.

strict_loads?()

Callback implementation for Ash.Resource.Calculation.strict_loads?/0.