diff --git a/lib/ash/actions/destroy/bulk.ex b/lib/ash/actions/destroy/bulk.ex index 51991016..bec52f09 100644 --- a/lib/ash/actions/destroy/bulk.ex +++ b/lib/ash/actions/destroy/bulk.ex @@ -93,6 +93,14 @@ defmodule Ash.Actions.Destroy.Bulk do changeset Ash.DataLayer.data_layer_can?(query.resource, :destroy_query) -> + opts = + Keyword.update( + opts, + :context, + %{private: query.context.private}, + &Map.put(&1, :private, query.context.private) + ) + Ash.Changeset.fully_atomic_changeset(query.resource, action, input, opts) true -> @@ -616,7 +624,7 @@ defmodule Ash.Actions.Destroy.Bulk do resource = opts[:resource] opts = Ash.Actions.Helpers.set_opts(opts, domain) - {_, opts} = + {context_cs, opts} = Ash.Actions.Helpers.set_context_and_get_opts(domain, Ash.Changeset.new(resource), opts) fully_atomic_changeset = @@ -631,6 +639,14 @@ defmodule Ash.Actions.Destroy.Bulk do {:not_atomic, "cannot atomically destroy a stream without a primary read action"} Ash.DataLayer.data_layer_can?(resource, :destroy_query) -> + opts = + Keyword.update( + opts, + :context, + %{private: context_cs.private}, + &Map.put(&1, :private, context_cs.private) + ) + Ash.Changeset.fully_atomic_changeset(resource, action, input, opts) true -> diff --git a/lib/ash/actions/update/bulk.ex b/lib/ash/actions/update/bulk.ex index 33a382b6..8fb68370 100644 --- a/lib/ash/actions/update/bulk.ex +++ b/lib/ash/actions/update/bulk.ex @@ -54,6 +54,14 @@ defmodule Ash.Actions.Update.Bulk do changeset Ash.DataLayer.data_layer_can?(query.resource, :update_query) -> + opts = + Keyword.update( + opts, + :context, + %{private: query.context.private}, + &Map.put(&1, :private, query.context.private) + ) + Ash.Changeset.fully_atomic_changeset(query.resource, action, input, opts) true -> @@ -801,7 +809,7 @@ defmodule Ash.Actions.Update.Bulk do opts = Ash.Actions.Helpers.set_opts(opts, domain) read_action = get_read_action(resource, opts) - {_, opts} = + {context_cs, opts} = Ash.Actions.Helpers.set_context_and_get_opts(domain, Ash.Changeset.new(resource), opts) fully_atomic_changeset = @@ -816,6 +824,14 @@ defmodule Ash.Actions.Update.Bulk do {:not_atomic, "cannot atomically update a stream without a primary read action"} Ash.DataLayer.data_layer_can?(resource, :update_query) -> + opts = + Keyword.update( + opts, + :context, + %{private: context_cs.context.private}, + &Map.put(&1, :private, context_cs.context.private) + ) + Ash.Changeset.fully_atomic_changeset(resource, action, input, opts) true -> diff --git a/lib/ash/actions/update/update.ex b/lib/ash/actions/update/update.ex index 937bb082..1ad5fa26 100644 --- a/lib/ash/actions/update/update.ex +++ b/lib/ash/actions/update/update.ex @@ -88,6 +88,7 @@ defmodule Ash.Actions.Update do opts |> Keyword.merge( assume_casted?: true, + context: changeset.context_changes, notify?: true, atomics: Keyword.merge( diff --git a/lib/ash/changeset/changeset.ex b/lib/ash/changeset/changeset.ex index b60940e2..44a2b030 100644 --- a/lib/ash/changeset/changeset.ex +++ b/lib/ash/changeset/changeset.ex @@ -63,6 +63,7 @@ defmodule Ash.Changeset do before_action: [], before_transaction: [], context: %{}, + context_changes: %{}, defaults: [], errors: [], params: %{}, @@ -544,6 +545,7 @@ defmodule Ash.Changeset do changeset = resource |> Ash.Changeset.new() + |> Map.put(:context, opts[:context] || %{}) |> Map.put(:params, params) |> Map.put(:action, action) |> Map.put(:action_type, action.type) @@ -1349,7 +1351,7 @@ defmodule Ash.Changeset do ```elixir change fn changeset, _ -> - Ash.Changeset.set_attribute(changeset, :score, changeset.data.score + 1) + Ash.Changeset.change_attribute(changeset, :score, changeset.data.score + 1) end ``` @@ -3553,8 +3555,15 @@ defmodule Ash.Changeset do def set_context(changeset, map) do %{changeset | context: Ash.Helpers.deep_merge_maps(changeset.context, map)} + |> store_context_changes(map) end + defp store_context_changes(%{phase: :pending} = changeset, map) do + %{changeset | context_changes: Ash.Helpers.deep_merge_maps(changeset.context_changes, map)} + end + + defp store_context_changes(changeset, _), do: changeset + @type manage_relationship_type :: :append_and_remove | :append | :remove | :direct_control | :create