fix: properly set notification_data from loaded record

This commit is contained in:
Zach Daniel 2023-06-14 20:40:04 -04:00
parent 3f3a588df8
commit a7d069ae30
3 changed files with 20 additions and 4 deletions

View file

@ -435,7 +435,13 @@ defmodule Ash.Actions.Helpers do
case api.load(result, query, opts) do
{:ok, result} ->
{:ok, result, Map.put(instructions, :notification_data, result)}
{:ok, result,
Map.update(
instructions,
:set_keys,
%{notification_data: result},
&Map.put(&1, :notification_data, result)
)}
{:error, error} ->
{:error, error}
@ -454,7 +460,7 @@ defmodule Ash.Actions.Helpers do
case api.load(result, query, opts) do
{:ok, result} ->
{:ok, result}
{:ok, result, %{set_keys: %{notification_data: result}}}
{:error, error} ->
{:error, error}

View file

@ -690,8 +690,8 @@ defmodule Ash.Actions.Load do
parent_data_path,
_parent_query_path,
_join_request_path,
actual_query,
_
_,
actual_query
)
when not is_nil(manual) do
{mod, opts} =

View file

@ -80,6 +80,8 @@ defmodule Ash.Test.NotifierTest do
defaults [:create, :read, :update, :destroy]
create :create_with_comment do
change load(:comments)
change fn changeset, _ ->
Ash.Changeset.after_action(changeset, fn _changeset, result ->
Comment
@ -191,6 +193,14 @@ defmodule Ash.Test.NotifierTest do
assert_receive {:notification, %Ash.Notifier.Notification{data: %Comment{name: "auto"}}}
end
test "the `load/1` change puts the loaded data into the notification" do
Post
|> Ash.Changeset.for_create(:create_with_comment, %{name: "foobar"})
|> Api.create!()
assert_receive {:notification, %Ash.Notifier.Notification{data: %Post{comments: [_]}}}
end
test "notifications use the data before its limited by a select statement" do
Comment
|> Ash.Changeset.new(%{name: "foobar"})