From 4bd63cca963494cd52711ce965c01b296a4b94fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 1 Dec 2023 08:49:44 +1100 Subject: [PATCH] Improve docs for order by on through preloads, closes #4330 --- lib/ecto/query.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ecto/query.ex b/lib/ecto/query.ex index 2228072ebc..06b3e8022a 100644 --- a/lib/ecto/query.ex +++ b/lib/ecto/query.ex @@ -2597,9 +2597,13 @@ defmodule Ecto.Query do Repo.all from p in Post, preload: [comments: ^comments_query] - Similarly, if you have a `:through` association, such as posts has many authors - through comments (`posts->comments->authors`), the query will only customize the - relationship between comments and authors, even if preloaded through posts. + Similarly, if you have a `:through` association, such as posts has many + `comments_authors` through comments (`posts->comments->comments_authors`), + the query will only customize the relationship between comments and + comments_authors, even if preloaded through posts. This means `order_by` + clauses on `:through` associations affect only the direct relationship + between `comments` and `comments_authors`, not between `posts` and + `comments_authors`. ## Preload functions