Skip to content

Commit ab438fb

Browse files
committed
Callout for unsupported eager load limit()
1 parent 2afa88f commit ab438fb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

eloquent-relationships.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ You may not always need every column from the relationships you are retrieving.
927927
<a name="constraining-eager-loads"></a>
928928
### Constraining Eager Loads
929929

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

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

942+
> {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.
943+
942944
<a name="lazy-eager-loading"></a>
943945
### Lazy Eager Loading
944946

0 commit comments

Comments
 (0)