Alternera.Resource.Transformers.AddReferenceKeys (alternera_resource_sdk v0.9.0)

Copy Markdown View Source

Names the records a resource refers to by their lookup key outside the proxy, never by their internal id.

For each belongs_to whose destination has a lookup_key (the resource itself included), with <field> = <relationship>_<key> (base_currency_code for belongs_to :base_currency to currencies keyed by code):

  • a public calculation <field>, the destination's key (Calculations.ReferenceKey), which the API, MCP and pipelines show in place of the id;
  • on every create and update action that accepts the reference's attribute, a public argument <field> of the key's type and Changes.SetReferenceByKey, which sets the attribute from it.

The list is persisted as :alternera_reference_keys and read with Alternera.Resource.Info.reference_keys/1; AddJsonApi hides the attribute and the relationship from the JSON:API document. The destination's key is read at compile time, so the destination compiles first: two resources that refer to each other both ways cannot both be keyed this way.

Summary

Functions

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.