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 byinstance_idand 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 viaAssignmentRelationshipafter the relationship hop. Each step walks back through the target's incoming assignments (target_id + aliasidentity, 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:cvcbring-up::circuitowns relationship, then:cvcassignment back to the CVC.singular?:(optional, defaultfalse) — unwrap to a single value when the consumer expects a 1-cardinality result (e.g. PRI's:avcor:unialiased 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
Callback implementation for Ash.Resource.Calculation.describe/1.
Callback implementation for Ash.Resource.Calculation.has_expression?/0.
Callback implementation for Ash.Resource.Calculation.init/1.
Callback implementation for Ash.Resource.Calculation.strict_loads?/0.
Functions
Callback implementation for Ash.Resource.Calculation.describe/1.
Callback implementation for Ash.Resource.Calculation.has_expression?/0.
Callback implementation for Ash.Resource.Calculation.init/1.
Callback implementation for Ash.Resource.Calculation.strict_loads?/0.