Skip to content

Commit 5b390c5

Browse files
committed
fix: only set sub_expr for literal values
1 parent 27e2594 commit 5b390c5

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

lib/expr.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,21 +2071,28 @@ defmodule AshSql.Expr do
20712071

20722072
validate_type!(query, type, arg1)
20732073

2074+
inner_bindings =
2075+
if is_map(arg1) && not is_struct(arg1) && Ash.Expr.expr?(arg1) do
2076+
set_location(bindings, :sub_expr)
2077+
else
2078+
bindings
2079+
end
2080+
20742081
{expr, acc} =
20752082
do_dynamic_expr(
20762083
query,
20772084
arg1,
2078-
set_location(bindings, :sub_expr),
2085+
inner_bindings,
20792086
embedded?,
20802087
acc,
20812088
{arg2, constraints}
20822089
)
20832090

20842091
case {type, expr} do
2085-
{{:parameterized, Ash.Type.Map.EctoType, _}, %Ecto.Query.DynamicExpr{}} ->
2092+
{{:parameterized, Ash.Type.Map.EctoType, []}, %Ecto.Query.DynamicExpr{}} ->
20862093
{expr, acc}
20872094

2088-
{{:parameterized, {Ash.Type.Map.EctoType, _}}, %Ecto.Query.DynamicExpr{}} ->
2095+
{{:parameterized, {Ash.Type.Map.EctoType, []}}, %Ecto.Query.DynamicExpr{}} ->
20892096
{expr, acc}
20902097

20912098
_ ->
@@ -2189,7 +2196,9 @@ defmodule AshSql.Expr do
21892196
type
21902197
) do
21912198
parent? = Map.get(bindings.parent_bindings, :parent_is_parent_as?, true)
2192-
new_bindings = set_location(Map.put(bindings.parent_bindings, :parent?, parent?), :sub_expr)
2199+
2200+
new_bindings =
2201+
set_location(Map.put(bindings.parent_bindings, :parent?, parent?), :sub_expr)
21932202

21942203
do_dynamic_expr(
21952204
%{query | __ash_bindings__: new_bindings},

0 commit comments

Comments
 (0)