Skip to content

Commit

Permalink
chore: small fixes for recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Feb 24, 2025
1 parent 41e37e2 commit 8de5bc7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/bindings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ defmodule AshSql.Bindings do
do: query

def default_bindings(query, resource, sql_behaviour, context) do
start_bindings = context[:data_layer][:start_bindings_at] || 0
default_start_bindings =
if context[:data_layer][:lateral_join_source] do
500
else
0
end

start_bindings = context[:data_layer][:start_bindings_at] || default_start_bindings

Map.put_new(query, :__ash_bindings__, %{
resource: resource,
Expand Down
8 changes: 4 additions & 4 deletions lib/expr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,10 @@ defmodule AshSql.Expr do
ref =
Ash.Actions.Read.add_calc_context_to_filter(
ref,
aggregate.context.actor,
aggregate.context.authorize?,
aggregate.context.tenant,
aggregate.context.tracer,
Map.get(aggregate.context, :actor),
Map.get(aggregate.context, :authorize?),
Map.get(aggregate.context, :tenant),
Map.get(aggregate.context, :tracer),
query.__ash_bindings__.domain,
resource,
parent_stack: query.__ash_bindings__[:parent_resources] || []
Expand Down
2 changes: 1 addition & 1 deletion lib/join.ex
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ defmodule AshSql.Join do
) do
if Ash.Actions.Read.Relationships.has_parent_expr?(
relationship,
query.__ash_bindings___[:context],
query.__ash_bindings__[:context],
query.__ash_bindings__[:domain]
) do
join_many_to_many_with_parent_expr(
Expand Down
12 changes: 8 additions & 4 deletions lib/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ defmodule AshSql.Query do
end

def set_context(resource, data_layer_query, sql_behaviour, context) do
start_bindings = context[:data_layer][:start_bindings_at] || 0
default_start_bindings =
if context[:data_layer][:lateral_join_source] do
500
else
0
end

start_bindings = context[:data_layer][:start_bindings_at] || default_start_bindings
data_layer_query = from(row in data_layer_query, as: ^start_bindings)

data_layer_query =
Expand Down Expand Up @@ -48,9 +55,6 @@ defmodule AshSql.Query do
true
)
})
# This is a hack, but surely there is just no way someone writes
# a 500 binding query as the base of a lateral join query...
|> Ash.Query.set_context(%{data_layer: %{start_bindings_at: 500}})
|> Ash.Query.set_tenant(lateral_join_source_query.tenant)
|> set_lateral_join_prefix(data_layer_query)
|> filter_for_records(data)
Expand Down

0 comments on commit 8de5bc7

Please sign in to comment.