From ab438fb01540449619b3244cc8f18e7850a3fdc4 Mon Sep 17 00:00:00 2001 From: Derek MacDonald Date: Sat, 19 Jan 2019 23:07:32 -0500 Subject: [PATCH] Callout for unsupported eager load limit() --- eloquent-relationships.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eloquent-relationships.md b/eloquent-relationships.md index 2c75fe0fde9..76ee1e09bcf 100644 --- a/eloquent-relationships.md +++ b/eloquent-relationships.md @@ -927,7 +927,7 @@ You may not always need every column from the relationships you are retrieving. ### 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%'); @@ -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. + ### Lazy Eager Loading