fix: properly determine reverse aggregate relationship

fix: ensure calculation modules are compiled
This commit is contained in:
Zach Daniel 2021-07-02 12:37:58 -04:00
parent 382d39175b
commit 5f05f683c2
2 changed files with 12 additions and 1 deletions

View file

@ -34,6 +34,7 @@ defmodule Ash.Actions.Sort do
calc -> calc ->
{module, opts} = calc.calculation {module, opts} = calc.calculation
Code.ensure_compiled(module)
if :erlang.function_exported(module, :expression, 2) do if :erlang.function_exported(module, :expression, 2) do
if Ash.DataLayer.data_layer_can?(resource, :expression_calculation_sort) do if Ash.DataLayer.data_layer_can?(resource, :expression_calculation_sort) do

View file

@ -141,8 +141,18 @@ defmodule Ash.Query.Aggregate do
List.first(relationship_path) List.first(relationship_path)
) )
path_for_checking =
relationship_path
|> tl()
|> Enum.reduce({[], aggregate_resource}, fn rel, {path, resource} ->
relationship = Ash.Resource.Info.relationship(resource, rel)
{[relationship | path], relationship.destination}
end)
|> elem(0)
|> Enum.reverse()
{in_query?, reverse_relationship} = {in_query?, reverse_relationship} =
case Load.reverse_relationship_path(relationship, tl(relationship_path)) do case Load.reverse_relationship_path(relationship, path_for_checking) do
:error -> :error ->
{ref_path == [] && can_be_in_query?, nil} {ref_path == [] && can_be_in_query?, nil}