DiffoExample.Calculations.ReverseInheritedCharacteristic (DiffoExample v0.2.2)

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

  • alias: (optional) — filter outgoing assignments by alias (the assignee's slot name). When omitted, all outgoing assignments are included.
  • characteristic_module: (required) — the typed characteristic Ash resource on each assignee (e.g. CardCharacteristic).

Example

# Shelf brings up the card characteristic from every card it's
# assigned a slot to, ordered by slot number.
calculate :cards, {:array, :map},
          {DiffoExample.Calculations.ReverseInheritedCharacteristic,
           [alias: :slot, characteristic_module: CardCharacteristic]}

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.