Ash FrameworkAF
Ash Framework5mo ago
5 replies
ajst7les

manage_relationship not creating many-to-many join records

I'm having trouble getting
manage_relationship
to work with a many-to-many relationship where the destination resource uses a non-standard primary key.

Setup


I have a many-to-many relationship between Device and Pass through a DeviceRegistration join table:

- Device: Standard resource with uuid_primary_key :id
- Pass: Uses uuid_primary_key :serial_number (not :id)
- DeviceRegistration: Join table with device_id and serial_number fields

Resource Configurations


Device Resource

defmodule MyApp.Device do
  use Ash.Resource

  actions do
    create :register do
      primary? true
      accept [:apple_device_id, :push_token]
      argument :passes, {:array, :uuid}, allow_nil?: true

      change manage_relationship(:passes, type: :append, value_is_key: :serial_number)

      upsert? true
      upsert_identity :unique_device_id
    end
  end

  relationships do
    many_to_many :passes, MyApp.Pass do
      through MyApp.DeviceRegistration
      source_attribute_on_join_resource :device_id
      destination_attribute :serial_number
      destination_attribute_on_join_resource :serial_number
    end
  end
end
Was this page helpful?