fix: remove belongs to related after action

This commit is contained in:
Zach Daniel 2021-08-02 11:02:38 -04:00
parent a3ee29c433
commit 80cedce2a2

View file

@ -235,21 +235,6 @@ defmodule Ash.Actions.ManagedRelationships do
case data do
{:ok, data} ->
current_value = Map.get(data, relationship.name)
case delete_unused(
data,
List.wrap(current_value),
relationship,
[],
[],
changeset,
actor,
opts
) do
{:ok, _, new_instructions} ->
instructions = new_instructions ++ instructions
if input in [nil || []] do
{:cont, {changeset, instructions}}
else
@ -303,10 +288,35 @@ defmodule Ash.Actions.ManagedRelationships do
)
end
end
|> case do
{:cont, {changeset, instructions}} ->
changeset =
Ash.Changeset.after_action(changeset, fn _, result ->
current_value = Map.get(data, relationship.name)
case delete_unused(
data,
List.wrap(current_value),
relationship,
[],
[],
changeset,
actor,
opts
) do
{:ok, _, new_instructions} ->
{:ok, result, new_instructions}
{:error, error} ->
{:halt, {Ash.Changeset.add_error(changeset, error), instructions}}
end
end)
{:cont, {changeset, instructions}}
{:halt, other} ->
{:halt, other}
end
{:error, error} ->
{:halt, {Ash.Changeset.add_error(changeset, error), instructions}}