File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -1174,9 +1174,22 @@ defmodule AshPostgres.Aggregate do
1174
1174
1175
1175
defp single_path? ( resource , [ relationship | rest ] ) do
1176
1176
relationship = Ash.Resource.Info . relationship ( resource , relationship )
1177
- relationship . type == :belongs_to && single_path? ( relationship . destination , rest )
1177
+
1178
+ ( relationship . type == :belongs_to ||
1179
+ has_one_with_identity? ( relationship ) ) &&
1180
+ single_path? ( relationship . destination , rest )
1181
+ end
1182
+
1183
+ defp has_one_with_identity? ( % { type: :has_one } = relationship ) do
1184
+ relationship . destination
1185
+ |> Ash.Resource.Info . identities ( )
1186
+ |> Enum . any? ( fn % { keys: keys } ->
1187
+ keys == [ relationship . destination_field ]
1188
+ end )
1178
1189
end
1179
1190
1191
+ defp has_one_with_identity? ( _ ) , do: false
1192
+
1180
1193
@ doc false
1181
1194
def aggregate_field ( aggregate , resource , _relationship_path , query ) do
1182
1195
case Ash.Resource.Info . field (
@@ -1192,10 +1205,6 @@ defmodule AshPostgres.Aggregate do
1192
1205
1193
1206
AshPostgres.Expr . validate_type! ( query , calc_type , "#{ inspect ( calculation . name ) } " )
1194
1207
1195
- if aggregate . context == % { } do
1196
- raise "what"
1197
- end
1198
-
1199
1208
{ :ok , query_calc } =
1200
1209
Ash.Query.Calculation . new (
1201
1210
calculation . name ,
You can’t perform that action at this time.
0 commit comments