fix: don't select destination attributes that don't exist

This commit is contained in:
Zach Daniel 2024-09-06 09:56:00 -04:00
parent b97040c9c4
commit be807aa9e2
2 changed files with 8 additions and 7 deletions

View file

@ -599,11 +599,12 @@ defmodule Ash.Actions.Read.Relationships do
end
defp select_destination_attribute(related_query, relationship) do
if Map.get(relationship, :manual) &&
!Ash.Resource.Info.attribute(
relationship.destination,
relationship.destination_attribute
) do
if Map.get(relationship, :no_attributes?) ||
(Map.get(relationship, :manual) &&
!Ash.Resource.Info.attribute(
relationship.destination,
relationship.destination_attribute
)) do
related_query
else
Ash.Query.ensure_selected(related_query, [relationship.destination_attribute])

View file

@ -194,7 +194,7 @@ defmodule Ash.Test.Resource.ResourceTest do
attributes do
uuid_primary_key :id
attribute :name, :string, public?: true
attribute :current_year, :integer, public?: :true
attribute :current_year, :integer, public?: true
end
relationships do
@ -220,7 +220,7 @@ defmodule Ash.Test.Resource.ResourceTest do
delorean = Ash.load!(delorean, [:next_machine])
assert delorean.next_machine.name == "San Dimas Phone Booth"
delorean = Ash.load!(delorean, [next_machine: [:name]])
delorean = Ash.load!(delorean, next_machine: [:name])
assert delorean.next_machine.name == "San Dimas Phone Booth"
end
end