Skip to content

Commit

Permalink
support subqueries in order_bys
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 16, 2024
1 parent 942f8ac commit 53cd867
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,17 @@ defmodule Ecto.Adapters.PostgresTest do
assert all(query) ==
~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x" ASC NULLS FIRST, s0."y" DESC NULLS FIRST}

order_by =
[asc: Ecto.Query.dynamic([], exists(from other_schema in "schema", where: other_schema.x == parent_as(:r).x, select: [other_schema.x]))]

query =
(from row in Schema, as: :r)
|> order_by(^order_by)
|> select([r], r.x)
|> plan()

assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY exists((SELECT ss0."x" AS "result" FROM "schema" AS ss0 WHERE (ss0."x" = s0."x")))}

query =
Schema
|> order_by([r], asc_nulls_last: r.x, desc_nulls_last: r.y)
Expand Down

0 comments on commit 53cd867

Please sign in to comment.