mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 21:13:10 +12:00
fix: properly set notification_data from loaded record
This commit is contained in:
parent
3f3a588df8
commit
a7d069ae30
3 changed files with 20 additions and 4 deletions
|
@ -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}
|
||||
|
|
|
@ -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} =
|
||||
|
|
|
@ -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"})
|
||||
|
|
Loading…
Reference in a new issue