read :get_and_claim do
get? true
prepare fn query, _ -> Ash.Query.lock(query, :for_update)
prepare build(limit: 1)
# my filters to get a matching row
prepare after_action(fn query, records, _context ->
with [record] <- records do
{
:ok,
[
record
|> Ash.Changeset.for_update(:claim)
|> Ash.update!()
]
}
end
end)
end
read :get_and_claim do
get? true
prepare fn query, _ -> Ash.Query.lock(query, :for_update)
prepare build(limit: 1)
# my filters to get a matching row
prepare after_action(fn query, records, _context ->
with [record] <- records do
{
:ok,
[
record
|> Ash.Changeset.for_update(:claim)
|> Ash.update!()
]
}
end
end)
end