DiffoExample. Calculations. ReverseInheritedCharacteristic
(DiffoExample v0.2.3)
Copy Markdown
View Source
Brings up typed characteristic values from instances this one has assigned to — the reverse of inheritance.
InheritedCharacteristic is the conventional direction: the assignee
inherits its characteristic from its assigner (you inherit from your
parents). This is the reverse: the assigner brings up the characteristic
of every assignee it's connected to (insanity is hereditary — you get
it from your kids).
Traverses OUTGOING AssignmentRelationship records (this instance as
source) optionally filtered by alias, then reads the typed characteristic
on each assignee.
Useful when the assigner wants to compose its assignees into its own view — e.g. a shelf bringing up the cards it has assigned slots to, ordered by slot number.
Worth yarning upstream alongside inherited_characteristic as a pair
of diffo-side DSL declarations.
Options
characteristic_module:(required) — the typed characteristic Ash resource on each assignee (e.g.CardCharacteristic).alias:(optional) — filter outgoing assignments by alias (the assignee's slot name). Use when every consumer follows the same aliasing convention.thing:(optional) — filter outgoing assignments bything(the pool's thing name, e.g.:slot,:port). Always set from the pool DSL declaration, so this is more robust thanalias:when consumers don't reliably name their slots. See[[assignment-direction-asymmetry]].
Specify either alias: or thing: (or both); omitting both includes
every outgoing assignment from this instance.
Examples
# Shelf brings up the card characteristic from every card it's
# assigned a slot to, ordered by slot number. Cards-as-assignees
# name their slot :slot when requesting.
calculate :cards, {:array, :map},
{DiffoExample.Calculations.ReverseInheritedCharacteristic,
[alias: :slot, characteristic_module: CardCharacteristic]}
# NTD brings up the UNI characteristic from every UNI it's assigned
# a port to. The UNIs may not have set an alias on their request,
# so filter by `thing` from the :ports pool declaration.
calculate :unis, {:array, :map},
{DiffoExample.Calculations.ReverseInheritedCharacteristic,
[thing: :port, characteristic_module: UniCharacteristic]}
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.