From 3567f960dd645e97c6daeee972790726ac106954 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 24 Sep 2024 08:44:27 -0400 Subject: [PATCH] fix: reselect required attributes unless `reuse_values?` is `true` --- lib/ash/actions/read/read.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ash/actions/read/read.ex b/lib/ash/actions/read/read.ex index 42e286128..d6319e98d 100644 --- a/lib/ash/actions/read/read.ex +++ b/lib/ash/actions/read/read.ex @@ -939,7 +939,14 @@ defmodule Ash.Actions.Read do query.select |> List.wrap() |> Kernel.--(Ash.Resource.Info.primary_key(query.resource)) - |> Enum.reject(&Ash.Resource.selected?(first, &1)) + + must_be_reselected = + if opts[:reuse_values?] do + must_be_reselected + |> Enum.reject(&Ash.Resource.selected?(first, &1)) + else + must_be_reselected + end {query, calculations_at_runtime, calculations_in_query} = Ash.Actions.Read.Calculations.deselect_known_forbidden_fields(