Skip to content

Commit

Permalink
fix: set relationship context on bulk destroy
Browse files Browse the repository at this point in the history
fixes #100
  • Loading branch information
zachdaniel committed Feb 3, 2025
1 parent 8495c32 commit 447794d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/ash_archival/resource/changes/archive_related.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
_ -> %{}
end

context =
opts[:context]
|> Kernel.||(%{})
|> Map.put(:ash_archival, true)
|> Ash.Helpers.deep_merge_maps(relationship.context || %{})

case related_query(data, relationship) do
{:ok, query} ->
Ash.bulk_destroy!(
query,
destroy_action,
arguments,
Keyword.update(
opts,
:context,
%{ash_archival: true},
&Map.put(&1, :ash_archival, true)
)
Keyword.put(opts, :context, context)
)

:error ->
Expand All @@ -118,12 +119,7 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
|> Ash.bulk_destroy!(
destroy_action,
%{},
Keyword.update(
opts,
:context,
%{ash_archival: true},
&Map.put(&1, :ash_archival, true)
)
Keyword.put(opts, :context, context)
)
end
end)
Expand All @@ -150,7 +146,8 @@ defmodule AshArchival.Resource.Changes.ArchiveRelated do
)
|> elem(1)
|> filter_by_keys(relationship, records)
|> Ash.Query.set_context(%{ash_archival: true})}
|> Ash.Query.set_context(%{ash_archival: true})
|> Ash.Query.set_context(relationship.context || %{})}
end
end

Expand Down

0 comments on commit 447794d

Please sign in to comment.