diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index f528622c..e0c41cec 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -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)