AshPrefixedId.Transformers.BelongsToAttribute (ash_prefixed_id v0.2.0)

View Source

Automatically updates FK attributes with the correct ObjectId type for belongs_to relationships pointing to AshPrefixedId resources.

Without this transformer, users must manually specify:

belongs_to :post, Post, attribute_type: Post.ObjectId

With this transformer, the attribute_type is inferred automatically:

belongs_to :post, Post  # attribute_type set to Post.ObjectId automatically

Implementation Note

This is registered as a transformer but conceptually acts as a post-processing step. It runs after Ash's BelongsToAttribute transformer has created the FK attributes, and after the DefineType persister has created ObjectId modules.

For self-referential relationships, the ObjectId module is created by the DefineType persister in the same compilation unit.

Summary

Functions

after?(_)

Callback implementation for Spark.Dsl.Transformer.after?/1.

after_compile?()

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

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.

transform(dsl_state)

Callback implementation for Spark.Dsl.Transformer.transform/1.