mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: cast calcs in query expressions
This commit is contained in:
parent
4ec454d4f1
commit
d2e5c71a6b
3 changed files with 10 additions and 6 deletions
|
@ -442,9 +442,10 @@ defmodule AshPostgres.Expr do
|
|||
},
|
||||
bindings,
|
||||
embedded?,
|
||||
type
|
||||
_type
|
||||
) do
|
||||
calculation = %{calculation | load: calculation.name}
|
||||
type = AshPostgres.Types.parameterized_type(calculation.type, [])
|
||||
|
||||
case Ash.Filter.hydrate_refs(
|
||||
calculation.module.expression(calculation.opts, calculation.context),
|
||||
|
@ -519,7 +520,7 @@ defmodule AshPostgres.Expr do
|
|||
} = ref,
|
||||
bindings,
|
||||
embedded?,
|
||||
type
|
||||
_type
|
||||
) do
|
||||
binding_to_replace =
|
||||
Enum.find_value(bindings.bindings, fn {i, binding} ->
|
||||
|
@ -533,6 +534,8 @@ defmodule AshPostgres.Expr do
|
|||
|> Map.delete(0)
|
||||
|> Map.update!(binding_to_replace, &Map.merge(&1, %{path: [], type: :root}))
|
||||
|
||||
type = AshPostgres.Types.parameterized_type(calculation.type, [])
|
||||
|
||||
case Ash.Filter.hydrate_refs(
|
||||
calculation.module.expression(calculation.opts, calculation.context),
|
||||
%{
|
||||
|
|
|
@ -248,6 +248,7 @@ defmodule AshPostgres.CalculationTest do
|
|||
test "calculations using if and literal boolean results can run" do
|
||||
Post
|
||||
|> Ash.Query.load(:was_created_in_the_last_month)
|
||||
|> Ash.Query.filter(was_created_in_the_last_month == true)
|
||||
|> Api.read!()
|
||||
end
|
||||
|
||||
|
|
|
@ -99,11 +99,11 @@ defmodule AshPostgres.Test.Post do
|
|||
:boolean,
|
||||
expr(
|
||||
# This is written in a silly way on purpose, to test a regression
|
||||
if fragment("(? <= (now() - '1 month'::interval))", created_at) do
|
||||
true
|
||||
else
|
||||
if(
|
||||
fragment("(? <= (now() - '1 month'::interval))", created_at),
|
||||
true,
|
||||
false
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue