Ash - how do I call this update action?

Hi All.

I’m currently tryinng to get my head around Ash. I’m slowly getting there but still coming across some things that I can’t quite grasp. So my current problem. I have the following update action:

 update :update do
      accept [:email, :name, :phone]
    end

I run the update action with…

customer |> Ash.Changeset.for_update(:update, %{name: "Bert", email: "bert@email.com"}) |> Ash.update

When I try and run :update, Ash kindly points out…

cannot atomically update a record without a primary read action or a configured `atomic_upgrade_with` action

So I have one read action which I update as the primary action and looks like this…

 read :read_by_id do
      primary? true
      argument :id, :integer, allow_nil?: false

      filter expr(id == ^arg(:id))
    end

The read action requires an id but I’ve no idea how to pass the id when calling the update action.

Any ideas?

P.S. Happy to be told this just isn’t the way things are done in Ash :smile:

cheers

Dave

We should actually just warn on this, this has been a footgun for a while. Your primary read action should not have any required arguments.

You almost certainly will just want

defaults [:read]

...

as your primary read.

Thanks @zachdaniel. I had originally got it working with a default read but it was bugging me how to get it working with arguments.

Thanks as well for the awesome framework :smile:

cheers

Ah, gotcha :slight_smile: So there is no way to set arguments for the read action that is used to do what we call an “atomic upgrade” of an action. We could potentially add some kind of hook to do that, but it is almost certainly more complex than it is worth to do that :laughing:

1 Like