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.
Description
FieldViaAssignedRelationship(#156) traverses anAssignmentRelationshipto 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.assignmentsmanually in application code.What we need
A calculation module
Diffo.Provider.Calculations.FieldFromAssignmentthat reads a named field directly from theAssignmentRelationshiprecord — no second hop to the source instance.alias:— optional atom. When provided, filtersAssignmentRelationshipbytarget_id = current.id, alias = alias. When omitted, returns the field from all assignments wheretarget_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
FieldViaAssignedRelationshipandFieldViaAliasedRelationship.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.