# `Alternera.Resource.Transformers.AddReferenceKeys`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_resource_sdk/lib/alternera/resource/transformers/add_reference_keys.ex#L1)

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.

# `after_compile?`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
