Skip to content

Commit 3a397bf

Browse files
authored
Add reference to custom function preloading in Repo module docs (#4560)
1 parent f069958 commit 3a397bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/ecto/repo.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,10 @@ defmodule Ecto.Repo do
11931193
query = from c in Comment, order_by: c.published_at
11941194
posts = Repo.preload posts, [comments: {query, [:replies, :likes]}]
11951195
1196-
The query given to preload may also preload its own associations.
1196+
# Use a function for custom preloading
1197+
posts = Repo.preload posts, [comments: fn post_ids -> fetch_comments_by_post_ids(post_ids) end]
1198+
1199+
The query given to preload may also preload its own associations. See the ["preload queries"](Ecto.Query.html#preload/3-preload-queries) and ["preload functions"](Ecto.Query.html#preload/3-preload-functions) section of the `Ecto.Query.preload/3` for details on those.
11971200
"""
11981201
@doc group: "Schema API"
11991202
@callback preload(structs_or_struct_or_nil, preloads :: term, opts :: Keyword.t()) ::

0 commit comments

Comments
 (0)