Skip to content

Commit b1fbd41

Browse files
committed
fix: set relationship context on bulk destroy
fixes #473
1 parent 8495c32 commit b1fbd41

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/ash_archival/resource/changes/archive_related.ex

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
8686
_ -> %{}
8787
end
8888

89+
context =
90+
opts[:context]
91+
|> Kernel.||(%{})
92+
|> Map.put(:ash_archival, true)
93+
|> Ash.Helpers.deep_merge_maps(relationship.context || %{})
94+
8995
case related_query(data, relationship) do
9096
{:ok, query} ->
9197
Ash.bulk_destroy!(
9298
query,
9399
destroy_action,
94100
arguments,
95-
Keyword.update(
96-
opts,
97-
:context,
98-
%{ash_archival: true},
99-
&Map.put(&1, :ash_archival, true)
100-
)
101+
Keyword.put(opts, :context, context)
101102
)
102103

103104
:error ->
@@ -118,12 +119,7 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
118119
|> Ash.bulk_destroy!(
119120
destroy_action,
120121
%{},
121-
Keyword.update(
122-
opts,
123-
:context,
124-
%{ash_archival: true},
125-
&Map.put(&1, :ash_archival, true)
126-
)
122+
Keyword.put(opts, :context, context)
127123
)
128124
end
129125
end)
@@ -150,7 +146,8 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
150146
)
151147
|> elem(1)
152148
|> filter_by_keys(relationship, records)
153-
|> Ash.Query.set_context(%{ash_archival: true})}
149+
|> Ash.Query.set_context(%{ash_archival: true})
150+
|> Ash.Query.set_context(relationship.context || %{})}
154151
end
155152
end
156153

0 commit comments

Comments
 (0)