Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Ecto.Schema.has_many/3 :preload_order option with MFA #4467

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ecto/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 856,13 @@ defmodule Ecto.Schema do
* `:where` - A filter for the association. See "Filtering associations" below.
It does not apply to `:through` associations.

* `:preload_order` - Sets the default `order_by` of the association.
It is used when the association is preloaded.
* `:preload_order` - Sets the default `order_by` when preloading the association.
It may be a keyword list/list of fields or an MFA tuple, such as `{Mod, fun, []}`.
Both cases must resolve to a valid `order_by` expression.
For example, if you set `Post.has_many :comments, preload_order: [asc: :content]`,
whenever the `:comments` associations is preloaded,
the comments will be ordered by the `:content` field.
See `Ecto.Query.order_by/3` for more examples.
See `Ecto.Query.order_by/3` to learn more about ordering expressions.

## Examples

Expand Down
Loading