# `Diffo.Provider.Calculations.FieldViaRelationship`
[🔗](https://github.com/diffo-dev/diffo/blob/v0.9.0/lib/diffo/provider/components/calculations/field_via_relationship.ex#L5)

Reads a field from target instances reached via a forward relationship edge.

Traverses both relationship resources — `DefinedSimpleRelationship` (a single
characteristic closed at creation) and the general `Relationship` (mutable
characteristics) — in the forward direction (filtering by `source_id = current.id`) and
returns the named field from each resolved target instance. An edge is one or the other;
this calc spans both so a consumer needn't know which storage the `:relate` action chose
(#222). 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 relationship 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]}

# `describe`

# `has_calculate?`

# `has_expression?`

# `init`

# `strict_loads?`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
