Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions lib/ash/actions/destroy/destroy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,15 @@ defmodule Ash.Actions.Destroy do
end
end
end
|> manage_relationships(domain, changeset,
actor: opts[:actor],
authorize?: opts[:authorize?]
)
|> then(fn result ->
case result do
{:ok, destroyed} ->
{:ok, destroyed, %{notifications: manage_notifications}} ->
if opts[:return_destroyed?] do
{:ok, destroyed, %{notifications: []}}
{:ok, destroyed, %{notifications: manage_notifications}}
|> Helpers.notify(changeset, opts)
|> Helpers.select(changeset)
|> Helpers.restrict_field_access(changeset)
Expand All @@ -257,7 +261,7 @@ defmodule Ash.Actions.Destroy do
select: changeset.action_select
})

{:ok, destroyed, %{notifications: []}}
{:ok, destroyed, %{notifications: manage_notifications}}
|> Helpers.notify(changeset, opts)
end

Expand Down Expand Up @@ -304,6 +308,37 @@ defmodule Ash.Actions.Destroy do
end
end

defp manage_relationships(
{:ok, destroyed, %{notifications: notifications}},
domain,
changeset,
engine_opts
) do
case manage_relationships({:ok, destroyed}, domain, changeset, engine_opts) do
{:ok, destroyed, info} ->
{:ok, destroyed, Map.update(info, :notifications, notifications, &(&1 ++ notifications))}

other ->
other
end
end

defp manage_relationships({:ok, destroyed}, domain, changeset, engine_opts) do
with {:ok, loaded} <-
Ash.Actions.ManagedRelationships.load(domain, destroyed, changeset, engine_opts),
{:ok, with_relationships, new_notifications} <-
Ash.Actions.ManagedRelationships.manage_relationships(
loaded,
changeset,
engine_opts[:actor],
engine_opts
) do
{:ok, with_relationships, %{notifications: new_notifications}}
end
end

defp manage_relationships(other, _, _, _), do: other

defp set_tenant(changeset) do
changeset =
case changeset.data do
Expand Down
4 changes: 4 additions & 0 deletions lib/ash/error/unknown/invalid_casted_value.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2019 ash contributors <https://github.com/ash-project/ash/graphs/contributors>
#
# SPDX-License-Identifier: MIT

defmodule Ash.Error.Unknown.InvalidCastedValue do
@moduledoc "Used when a value fails to dump to its native (storage) format"

Expand Down
4 changes: 4 additions & 0 deletions lib/ash/error/unknown/invalid_stored_value.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2019 ash contributors <https://github.com/ash-project/ash/graphs/contributors>
#
# SPDX-License-Identifier: MIT

defmodule Ash.Error.Unknown.InvalidStoredValue do
@moduledoc "Used when a stored value fails to be cast from the data layer"

Expand Down
Loading