fix: don't consider ash field signals as present

This commit is contained in:
Zach Daniel 2024-01-05 12:30:21 -05:00
parent 426e471cbe
commit 16818f1f14

View file

@ -1209,8 +1209,15 @@ defmodule Ash.Changeset do
*will* be set by `manage_relationship` even if it isn't currently being set. *will* be set by `manage_relationship` even if it isn't currently being set.
""" """
def present?(changeset, attribute) do def present?(changeset, attribute) do
belongs_to_attr_of_rel_being_managed?(attribute, changeset, true) || arg_or_attribute_value =
not is_nil(Ash.Changeset.get_argument_or_attribute(changeset, attribute)) case Ash.Changeset.get_argument_or_attribute(changeset, attribute) do
%Ash.NotLoaded{} -> nil
%Ash.ForbiddenField{} -> nil
other -> other
end
not is_nil(arg_or_attribute_value) ||
belongs_to_attr_of_rel_being_managed?(attribute, changeset, true)
end end
def prepare_changeset_for_action(changeset, action, opts) do def prepare_changeset_for_action(changeset, action, opts) do
@ -2000,8 +2007,10 @@ defmodule Ash.Changeset do
def require_values(changeset, _, _, _), do: changeset def require_values(changeset, _, _, _), do: changeset
defp belongs_to_attr_of_rel_being_managed?(attribute, changeset, only_if_relating? \\ false) do defp belongs_to_attr_of_rel_being_managed?(attribute, changeset, only_if_relating? \\ false) do
do_belongs_to_attr_of_rel_being_managed?(changeset, attribute) || IO.inspect(do_belongs_to_attr_of_rel_being_managed?(changeset, attribute)) ||
IO.inspect(
belongs_to_attr_of_being_managed_through?(changeset, attribute, only_if_relating?) belongs_to_attr_of_being_managed_through?(changeset, attribute, only_if_relating?)
)
end end
defp do_belongs_to_attr_of_rel_being_managed?(changeset, attribute) do defp do_belongs_to_attr_of_rel_being_managed?(changeset, attribute) do