Skip to content

FieldViaAliasedRelationship — read a field from a target instance via an aliased DefinedSimpleRelationship #157

@matt-beanland

Description

@matt-beanland

Description

There is no general-purpose way to read a base field from the target instance of a DefinedSimpleRelationship filtered by alias. Resources that need to surface such a field must write bespoke calculation modules, repeating the same forward-traversal logic each time.

This is the forward-relationship counterpart to FieldViaAssignedRelationship (#156), which traverses AssignmentRelationship in the reverse direction. Together they cover the two primary aliased traversal forms in the diffo graph.

What we need

A calculation module Diffo.Provider.Calculations.FieldViaAliasedRelationship with arguments mirroring inherited_place / inherited_party:

  • alias: — the alias to filter on, matching DefinedSimpleRelationship records where source_id = current.id, alias = step. Optional — when omitted, traverses all outgoing DefinedSimpleRelationship records.
  • field: — the field name to read from the resolved target instance.

Returns a list of field values.

# Aliased — field from the target of the :provides relationship
calculate :provider_name, :string,
  {Diffo.Provider.Calculations.FieldViaAliasedRelationship, [alias: :provides, field: :name]}

# Unaliased — field from all directly related targets
calculate :related_names, {:array, :string},
  {Diffo.Provider.Calculations.FieldViaAliasedRelationship, [field: :name]}

Why it matters

Both aliased traversal forms — via assignment and via named relationship — are needed for the demo. FieldViaAssignedRelationship covers the reverse (consumer reading from provider); FieldViaAliasedRelationship covers the forward (provider reading from its targets). Both are required this release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions