mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: use synonymous_relationship_path
when looking up ref bindings
This commit is contained in:
parent
af8d8dbcac
commit
ef96cd541e
4 changed files with 33 additions and 5 deletions
14
lib/expr.ex
14
lib/expr.ex
|
@ -1492,13 +1492,23 @@ defmodule AshPostgres.Expr do
|
|||
|
||||
defp ref_binding(%{attribute: %Ash.Resource.Attribute{}} = ref, bindings) do
|
||||
Enum.find_value(bindings.bindings, fn {binding, data} ->
|
||||
data.path == ref.relationship_path && data.type in [:inner, :left, :root] && binding
|
||||
data.type in [:inner, :left, :root] &&
|
||||
Ash.SatSolver.synonymous_relationship_paths?(
|
||||
bindings.resource,
|
||||
data.path,
|
||||
ref.relationship_path
|
||||
) && binding
|
||||
end)
|
||||
end
|
||||
|
||||
defp ref_binding(%{attribute: %Ash.Query.Aggregate{}} = ref, bindings) do
|
||||
Enum.find_value(bindings.bindings, fn {binding, data} ->
|
||||
data.path == ref.relationship_path && data.type in [:inner, :left, :root] && binding
|
||||
data.type in [:inner, :left, :root] &&
|
||||
Ash.SatSolver.synonymous_relationship_paths?(
|
||||
bindings.resource,
|
||||
data.path,
|
||||
ref.relationship_path
|
||||
) && binding
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
18
lib/join.ex
18
lib/join.ex
|
@ -30,6 +30,21 @@ defmodule AshPostgres.Join do
|
|||
relationship_paths \\ nil,
|
||||
path \\ [],
|
||||
source \\ nil
|
||||
)
|
||||
|
||||
# simple optimization for common cases
|
||||
def join_all_relationships(query, filter, _opts, relationship_paths, _path, _source)
|
||||
when is_nil(relationship_paths) and filter in [nil, true, false] do
|
||||
{:ok, query}
|
||||
end
|
||||
|
||||
def join_all_relationships(
|
||||
query,
|
||||
filter,
|
||||
opts,
|
||||
relationship_paths,
|
||||
path,
|
||||
source
|
||||
) do
|
||||
relationship_paths =
|
||||
cond do
|
||||
|
@ -49,6 +64,8 @@ defmodule AshPostgres.Join do
|
|||
|> to_joins(filter, query.__ash_bindings__.resource)
|
||||
|
||||
true ->
|
||||
id = System.unique_integer([:monotonic, :positive])
|
||||
|
||||
filter
|
||||
|> Ash.Filter.relationship_paths()
|
||||
|> to_joins(filter, query.__ash_bindings__.resource)
|
||||
|
@ -130,6 +147,7 @@ defmodule AshPostgres.Join do
|
|||
|
||||
defp to_joins(paths, filter, resource) do
|
||||
paths
|
||||
|> Enum.reject(&(&1 == []))
|
||||
|> Enum.map(fn path ->
|
||||
if can_inner_join?(path, filter) do
|
||||
{:inner,
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -204,7 +204,7 @@ defmodule AshPostgres.MixProject do
|
|||
{:ecto, "~> 3.9"},
|
||||
{:jason, "~> 1.0"},
|
||||
{:postgrex, ">= 0.0.0"},
|
||||
{:ash, ash_version("~> 2.17 and >= 2.17.2")},
|
||||
{:ash, ash_version("~> 2.17 and >= 2.17.3")},
|
||||
{:benchee, "~> 1.1", only: [:dev, :test]},
|
||||
{:git_ops, "~> 2.5", only: [:dev, :test]},
|
||||
{:ex_doc, github: "elixir-lang/ex_doc", only: [:dev, :test], runtime: false},
|
||||
|
|
|
@ -49,10 +49,10 @@ defmodule AshPostgres.Test.ComplexCalculations.Channel do
|
|||
expr(
|
||||
cond do
|
||||
first_member.user_id == ^actor(:id) ->
|
||||
second_member_name
|
||||
first_member_name
|
||||
|
||||
second_member.user_id == ^actor(:id) ->
|
||||
first_member_name
|
||||
second_member_name
|
||||
|
||||
true ->
|
||||
first_member_name <> ", " <> second_member_name
|
||||
|
|
Loading…
Reference in a new issue