improvement: support latest ash changes

This commit is contained in:
Zach Daniel 2024-01-19 00:12:50 -05:00
parent 97847da734
commit f20a07f54b
3 changed files with 16 additions and 5 deletions

View file

@ -1,2 +1,2 @@
erlang 26.0.2
elixir 1.15.4
elixir 1.16.0

View file

@ -48,7 +48,16 @@ defmodule AshPostgres.Sort do
calcs =
Enum.flat_map(sort, fn
{%Ash.Query.Calculation{} = calculation, _} ->
[calculation]
{:ok, expression} =
calculation.opts
|> calculation.module.expression(calculation.context)
|> Ash.Filter.hydrate_refs(%{
resource: resource,
parent_stack: query.__ash_bindings__[:parent_resources] || [],
public?: false
})
[{calculation, Ash.Filter.move_to_relationship_path(expression, relationship_path)}]
_ ->
[]
@ -59,7 +68,7 @@ defmodule AshPostgres.Sort do
query,
%Ash.Filter{
resource: resource,
expression: calcs
expression: Enum.map(calcs, &elem(&1, 1))
},
left_only?: true
)
@ -84,9 +93,7 @@ defmodule AshPostgres.Sort do
|> calc.module.expression(calc.context)
|> Ash.Filter.hydrate_refs(%{
resource: resource,
aggregates: query.__ash_bindings__.aggregate_defs,
parent_stack: query.__ash_bindings__[:parent_resources] || [],
calculations: %{},
public?: false
})
|> Ash.Filter.move_to_relationship_path(relationship_path)

View file

@ -239,6 +239,8 @@ defmodule AshPostgres.Test.Post do
expr(latest_comment_created_at > fragment("now()") || type(false, :boolean))
)
calculate(:price_times_2, :integer, expr(price * 2))
calculate(
:was_created_in_the_last_month,
:boolean,
@ -333,6 +335,8 @@ defmodule AshPostgres.Test.Post do
uniq?(true)
end
count(:count_of_ratings, :ratings)
list :comment_titles_with_5_likes, :comments, :title do
sort(title: :asc_nils_last)
filter(expr(likes >= 5))