mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
chore: ensure changeset is set on atomic upgraded errors
docs: update livebook
This commit is contained in:
parent
1d519e37e0
commit
09cff72d03
2 changed files with 15 additions and 22 deletions
|
@ -20,12 +20,12 @@ For more information, see the documentation for `Ash.Resource.Change.OptimisticL
|
|||
|
||||
1. Add a `:version` attribute to your resource, of type `:integer`, with a default of `1` and `allow_nil?: false`
|
||||
2. Add `change optimistic_lock(:version)`. Where you add it depends on which actions you want to prevent concurrent writes for:
|
||||
- If you want optimistic locking to occur for _specific actions_:
|
||||
* If you want optimistic locking to occur for _specific actions_:
|
||||
1. Add `change optimistic_lock(:version)` to those specific actions
|
||||
- If you want optimistic locking to occur for _all action types_:
|
||||
* If you want optimistic locking to occur for _all action types_:
|
||||
1. Add a global `changes` block to the resource, if you do not have one
|
||||
2. Add `change optimistic_lock(:version), on: [:create, :update, :destroy]`
|
||||
- If you want to apply optimistic locking to _many but not all actions_:
|
||||
* If you want to apply optimistic locking to _many but not all actions_:
|
||||
1. Add a global `changes` block to the resource, if you do not have one
|
||||
2. Add `change optimistic_lock(:version), where: action_is([:action1, :action2, :action3])`
|
||||
|
||||
|
@ -83,7 +83,7 @@ end
|
|||
<!-- livebook:{"output":true} -->
|
||||
|
||||
```
|
||||
{:module, Domain, <<70, 79, 82, 49, 0, 2, 14, ...>>,
|
||||
{:module, Domain, <<70, 79, 82, 49, 0, 2, 1, ...>>,
|
||||
[
|
||||
Ash.Domain.Dsl.Resources.Resource,
|
||||
Ash.Domain.Dsl.Resources.Options,
|
||||
|
@ -110,9 +110,7 @@ Domain.update_address(address, %{county: "Miami-Dade"})
|
|||
```
|
||||
{:error,
|
||||
%Ash.Error.Invalid{
|
||||
changeset: nil,
|
||||
query: nil,
|
||||
action_input: nil,
|
||||
changeset: "#Changeset<>",
|
||||
errors: [
|
||||
%Ash.Error.Changes.StaleRecord{
|
||||
resource: "Address",
|
||||
|
@ -124,13 +122,7 @@ Domain.update_address(address, %{county: "Miami-Dade"})
|
|||
stacktrace: #Splode.Stacktrace<>,
|
||||
class: :invalid
|
||||
}
|
||||
],
|
||||
splode: Ash.Error,
|
||||
bread_crumbs: [],
|
||||
vars: [],
|
||||
path: [],
|
||||
stacktrace: #Splode.Stacktrace<>,
|
||||
class: :invalid
|
||||
]
|
||||
}}
|
||||
```
|
||||
|
||||
|
@ -157,7 +149,7 @@ end
|
|||
```
|
||||
#Address<
|
||||
__meta__: #Ecto.Schema.Metadata<:loaded>,
|
||||
id: "9f5d247e-fc44-41d1-80b4-8553c63855bb",
|
||||
id: "91e552e1-3307-4d68-969f-1b7e6651e695",
|
||||
version: 3,
|
||||
state: "NC",
|
||||
county: "Miami-Dade",
|
||||
|
|
|
@ -171,11 +171,12 @@ defmodule Ash.Actions.Update do
|
|||
Ash.Error.Changes.StaleRecord.exception(
|
||||
resource: fully_atomic_changeset.resource,
|
||||
filters: Map.take(changeset.data, primary_key)
|
||||
)
|
||||
),
|
||||
changeset: atomic_changeset
|
||||
)}
|
||||
|
||||
%Ash.BulkResult{status: :error, errors: errors} ->
|
||||
{:error, Ash.Error.to_error_class(errors)}
|
||||
{:error, Ash.Error.to_error_class(errors, changeset: atomic_changeset)}
|
||||
end
|
||||
|
||||
other ->
|
||||
|
|
Loading…
Reference in a new issue