DiffoExample.Calculations.InheritedCharacteristicViaRelationship (DiffoExample v0.2.3)

Copy Markdown View Source

Brings up typed characteristic values from target instances reached via forward Diffo.Provider.Relationship edges (source → target), optionally filtered by type: and/or alias:.

Sibling to InheritedCharacteristicViaAssignment, which performs the analogous traversal over AssignmentRelationship edges. Pick the right calc by the kind of edge being traversed — relationship vs. assignment.

Use this when the edge between the consuming instance and the target was created by a :relate action (a Provider.Relationship record). Use InheritedCharacteristicViaAssignment when the edge was created by the Assigner (an AssignmentRelationship record).

Local-to-this-repo for now. Worth yarning upstream alongside the assignment variant as a pair of provider-side calcs.

Options

  • characteristic_module: (required) — the typed characteristic Ash resource on the final source (e.g. NniCharacteristic). The calc queries this resource by instance_id and returns the .value.
  • type: (optional) — filter relationships by type atom (e.g. :contains).
  • alias: (optional) — filter relationships by alias atom (e.g. :avc).
  • then_via: (optional) — list of consumer-alias atoms to walk back via AssignmentRelationship after the relationship hop. Each step walks back through the target's incoming assignments (target_id + alias identity, so each step has cardinality ≤1). Aliases name the upstream related resource each consumer is part of. Use this for mixed paths — one relationship hop followed by one or more assignment hops — e.g. PRI's :cvc bring-up: :circuit owns relationship, then :cvc assignment back to the CVC.
  • singular?: (optional, default false) — unwrap to a single value when the consumer expects a 1-cardinality result (e.g. PRI's :avc or :uni aliased owns-relationship). Declare the calc's return type as :map (rather than {:array, :map}) when using this option.

Examples

# NniGroup brings up the typed characteristic of every NNI it
# comprises — forward traversal of :contains relationships, returns
# a list of NniCharacteristic values.
calculate :nnis, {:array, :map},
          {DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
           [type: :contains, characteristic_module: NniCharacteristic]}

# PRI brings up the singular AVC it owns — PRI calls this related
# resource :circuit (its domain role), set as the alias on PRI's
# owns relationship.
calculate :avc, :map,
          {DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
           [alias: :circuit, characteristic_module: AvcCharacteristic, singular?: true]}

# PRI brings up the singular CVC two-hop — :circuit owns relationship
# from PRI to AVC, then back via the AVC's :cvc consumer-alias
# assignment from CVC.
calculate :cvc, :map,
          {DiffoExample.Calculations.InheritedCharacteristicViaRelationship,
           [alias: :circuit, then_via: [:cvc],
            characteristic_module: CvcCharacteristic, singular?: true]}

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.