Skip to content

FieldFromAssignment — read a field directly from an AssignmentRelationship record #158

@matt-beanland

Description

@matt-beanland

Description

FieldViaAssignedRelationship (#156) traverses an AssignmentRelationship to read a field on the source instance. But the relationship record itself carries useful fields — value, thing, pool, alias — and there is no general-purpose way to surface these as calculations on the consuming instance.

The pattern is common: a service wants to know which port value was assigned to it, or under which pool, without loading and picking through instance.assignments manually in application code.

What we need

A calculation module Diffo.Provider.Calculations.FieldFromAssignment that reads a named field directly from the AssignmentRelationship record — no second hop to the source instance.

  • alias: — optional atom. When provided, filters AssignmentRelationship by target_id = current.id, alias = alias. When omitted, returns the field from all assignments where target_id = current.id.
  • field: — the field to read from the relationship record (:value, :thing, :pool, :alias, etc.).

Returns a list of field values, consistent with FieldViaAssignedRelationship and FieldViaAliasedRelationship.

# Port number assigned to this service under the :primary slot
calculate :assigned_port, :integer,
  {Diffo.Provider.Calculations.FieldFromAssignment, [alias: :primary, field: :value]}

# Pool name for any assignment on this instance
calculate :assignment_pool, :atom,
  {Diffo.Provider.Calculations.FieldFromAssignment, [field: :pool]}

Why it matters

Completes the trio with #156 and #157. Together the three calculations cover reading from the relationship record itself, from the source instance via assignment, and from the target instance via aliased relationship — the full set of traversal patterns needed for the demo.

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