Load Preparations Not Applying to Embedded Resource

I created a calculation that should always be present in an embedded resource and added a preparation to ensure it is always loaded. However, it does not seem to be working. Is this the intended behavior?

defmodule MyApp.Resources.Addr do
  use Ash.Resource, data_layer: :embedded, domain: MyApp.Domain

  attributes do
    attribute :addr1, :string
    attribute :addr2, :string
    attribute :postal_code, :string
  end

  
  calculations do
    calculate :format, :string, fn addrs, _ ->
      addrs
      |> Enum.map(fn %{addr1: addr1, addr2: addr2, postal_code: postal_code} ->
        ["(#{postal_code})", addr1, addr2] |> Enum.reject(&is_nil/1) |> Enum.join(" ")
      end)
    end
  end

  # not working with embedded resource
  preparations do
    prepare build(load: [:format])
  end
end

:thinking: Potentially a bug, I’m not sure if I considered that case while implementing. However you can load data on embeds with:

attribute :addr, MyApp.Resources.Addr do
  constraints [load: [:format]]
end
2 Likes