Skip to content

Commit

Permalink
fix: set tenant at start of query build (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel-io committed Nov 2, 2021
1 parent 7661d3d commit 3b06998
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ash/query/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ defmodule Ash.Query do

@doc "Return the underlying data layer query for an ash query"
def data_layer_query(%{resource: resource, api: api} = ash_query, opts \\ []) do
query = Ash.DataLayer.resource_to_query(resource, api)
query = opts[:initial_query] || Ash.DataLayer.resource_to_query(resource, api)

filter_aggregates =
if ash_query.filter do
Expand All @@ -1683,11 +1683,12 @@ defmodule Ash.Query do
aggregates = Enum.uniq_by(filter_aggregates ++ sort_aggregates, & &1.name)

with {:ok, query} <-
add_tenant(query, ash_query),
{:ok, query} <-
add_aggregates(query, ash_query, aggregates),
{:ok, query} <-
Ash.DataLayer.sort(query, ash_query.sort, resource),
{:ok, query} <- maybe_filter(query, ash_query, opts),
{:ok, query} <- add_tenant(query, ash_query),
{:ok, query} <-
Ash.DataLayer.limit(query, ash_query.limit, resource),
{:ok, query} <-
Expand Down

0 comments on commit 3b06998

Please sign in to comment.