Ash FrameworkAF
Ash Framework6mo ago
3 replies
bhelms

Atomic array removal

Greetings!

I'm attempting to remove an element from a string array attribute from all records that have it, but do it atomically with psql's array_remove. I have the following change:
attribute :thing_ids, {:array, :string}, public?: true

update :remove_thing do
  argument :thing_id, :string, allow_nil?: false
  filter expr(fragment("? = ANY(?)", ^arg(:thing_id), thing_ids))

  change atomic_update(
            :thing_ids,
            expr(fragment("array_remove(?, ?)", ^atomic_ref(:thing_ids), ^arg(:thing_id)))
          )
end


When I try: Ash.bulk_update!(MyResource, :remove_thing, %{thing_id: thing_id}), it returns the following error:
Could not use ":atomic": Cannot atomically update MyResource.thing_ids: Cannot cast a non-literal list atomically

Is this just not doable or am I doing it wrong?

Thanks
Was this page helpful?