How to run custom resource extension before validators
Hi there,
I'm writing my first
Ash.Resource
Ash.Resource
extension and having some issues I don't know how to solve. This is my simple extension so far:
defmodule EKG.Extensions.ScenePlaceable do use Spark.Dsl.Extension, transformers: [EKG.Extensions.ScenePlaceable.AddAttributes]enddefmodule EKG.Extensions.ScenePlaceable.AddAttributes do use Spark.Dsl.Transformer def transform(dsl_state) do dsl_state |> Ash.Resource.Builder.add_new_attribute(:x, :integer, description: "X coordinate position", allow_nil?: false, public?: true, constraints: [min: 0] ) # ... other attrs endend
defmodule EKG.Extensions.ScenePlaceable do use Spark.Dsl.Extension, transformers: [EKG.Extensions.ScenePlaceable.AddAttributes]enddefmodule EKG.Extensions.ScenePlaceable.AddAttributes do use Spark.Dsl.Transformer def transform(dsl_state) do dsl_state |> Ash.Resource.Builder.add_new_attribute(:x, :integer, description: "X coordinate position", allow_nil?: false, public?: true, constraints: [min: 0] ) # ... other attrs endend
All it does is add some attributes to the resource. But when I add
EKG.Extensions.ScenePlaceable
EKG.Extensions.ScenePlaceable
to the list of extensions of my resource I'm now getting this compile error:
== Compilation error in file lib/ekg/scenes/scene_widget.ex ==** (Spark.Error.DslError) [EKG.Scenes.SceneWidget]actions -> update -> accept: Cannot accept [:x, :y, :width, :height, :z_index], because they are not attributes."
== Compilation error in file lib/ekg/scenes/scene_widget.ex ==** (Spark.Error.DslError) [EKG.Scenes.SceneWidget]actions -> update -> accept: Cannot accept [:x, :y, :width, :height, :z_index], because they are not attributes."
So looks like that validation is running before my extension has a chance to add the attributes? As far as I'm aware the docs don't mention how to configure an extension to get around this issue, but I'm sure the fix is easy. Thank you for your help!
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.