How To Save Belongs To - Ash 3.0 Error ""Ash.Resource.Change.ManageRelationship does not implement `atomic/3`"

How to do I save belongs_to relationship?

I have Item and UnitMeasure resource. Item resource belongs to the UnitMeasure Resource.

Here is the relationship definition for the Item resource:

  relationships do
    belongs_to :unit_measure, Kamaro.Stock.UnitMeasure do
      attribute_writable? true
    end
  end

According to Ash Relationship Tutorial, the following code should work

item 
|> Ash.Changeset.for_update(:update, %{unit_measure_id: unit.id}) 
|> Ash.update()

But it is giving me an error that:

{:error,
 %Ash.Error.framework{
   errors: [
     %Ash.Error.Framework.MustBeAtomic{
       resource: Kamaro.Stock.Item,
       action: :update,
       reason: "Ash.Resource.Change.ManageRelationship does not implement `atomic/3`",
       splode: Ash.Error,
       bread_crumbs: [],
       vars: [],
       path: [],
       stacktrace: #Splode.Stacktrace<>,
       class: :framework
     }
   ]
 }}

That tutorial may be a little out of date as it references Ash 2. It should work as-is though - have you customized the update action in any way, and added a manage_relationship call? If so, you can safely remove it as it’s not necessary.

1 Like

It worked after:

  1. I removed manage_relationship
  2. I added :unit_measure_id in the default_accept
1 Like