Skip to content
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
4 changes: 3 additions & 1 deletion eloquent-relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ You may not always need every column from the relationships you are retrieving.
<a name="constraining-eager-loads"></a>
### Constraining Eager Loads

Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:
Sometimes you may wish to eager load a relationship, but also specify additional query conditions for the eager loading query. Here's an example:

$users = App\User::with(['posts' => function ($query) {
$query->where('title', 'like', '%first%');
Expand All @@ -939,6 +939,8 @@ In this example, Eloquent will only eager load posts where the post's `title` co
$query->orderBy('created_at', 'desc');
}])->get();

> {note} Query builder methods `limit()` and `take()` cannot be used when constraining eager loads. One database query is run to eager load a relation so the limited results will be for _all_ models, not _per_ model.

<a name="lazy-eager-loading"></a>
### Lazy Eager Loading

Expand Down