Ash FrameworkAF
Ash Framework3y ago
9 replies
Blibs

Which action to use to update/delete multiple rows at the same time?

I was wondering which action type should I use to update or delete multiple rows of a resource?

For example, let's say I have a resource called
Post
, and I want to have an action where I update all posts from that user.

At first glance, I would use the :update action for that. But it seems that both :create, :update and :destroy actions are only meant to run with only one resource/changeset at a time.

So, if I would create an :update action, I would need to pass an empty changeset of a
Post
which doesn't mean anything to what I'm trying to do since inside the action I would ignore that changeset entirely, fetch all posts filtered by the actor
id
and
update
them.

The action that makes more sense for that is :read since a :read action don't expect a changeset as an input. But, at the same time it seems wrong to use a :read action to update rows...

So, in the end, what is the most idiomatic way to do something like this with Ash?
Was this page helpful?