Skip to content

Commit

Permalink
Add reference to custom function preloading in Repo module docs (#4560)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel authored Dec 24, 2024
1 parent f069958 commit 3a397bf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/ecto/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,10 @@ defmodule Ecto.Repo do
query = from c in Comment, order_by: c.published_at
posts = Repo.preload posts, [comments: {query, [:replies, :likes]}]
The query given to preload may also preload its own associations.
# Use a function for custom preloading
posts = Repo.preload posts, [comments: fn post_ids -> fetch_comments_by_post_ids(post_ids) end]
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.
"""
@doc group: "Schema API"
@callback preload(structs_or_struct_or_nil, preloads :: term, opts :: Keyword.t()) ::
Expand Down

0 comments on commit 3a397bf

Please sign in to comment.