How to Extract a Relationship into a Separate Module for Reuse in `Ash`?

You can centralize it by writing an extension, although for just one relationship it may be sort of a nuclear option :slight_smile:

defmodule YourApp.CustomFields do
  use Spark.Dsl.Extension, 
    transformers: [YourApp.CustomFields.Transformers.AddCustomFields]
end

defmodule YourApp.CustomFields.Transformers.AddCustomFields do
  use Spark.Dsl.Transformer

  def transform(dsl) do
    dsl
    |> Ash.Resource.Builder.add_new_relationship(:has_many, :fields, MyApp>Fields.FieldResourceRecord)
  end
end

Then you can do

use Ash.Resource, extensions: [YourApp.CustomFields]