i'm trying to get user documents along with first three related meeting documents.
User::with(
[
'meetings' => function($query) {
$query->take(3);
}
]
)->get();
user-meeting relation in App\Models\User.php:
public function meetings(){
return $this->hasMany(Meeting::class);
}
but as a result, i only get meetings related to the first user:
[
{
"_id": "63123a4906650000d2006de2",
...
"meetings": [
{
"_id": "63123e0590530000860042bd",
"user_id": "63123a4906650000d2006de2",
"start_time": "2022-08-29T12:00:00.000000Z",
"updated_at": "2022-09-02T17:31:49.601000Z",
"created_at": "2022-09-02T17:31:49.601000Z"
},
{
"_id": "63123e0590530000860042be",
"user_id": "63123a4906650000d2006de2",
"start_time": "2022-08-29T12:15:00.000000Z",
"updated_at": "2022-09-02T17:31:49.602000Z",
"created_at": "2022-09-02T17:31:49.602000Z"
},
{
"_id": "63123e0590530000860042bf",
"user_id": "63123a4906650000d2006de2",
"start_time": "2022-08-29T12:30:00.000000Z",
"updated_at": "2022-09-02T17:31:49.603000Z",
"created_at": "2022-09-02T17:31:49.603000Z"
}
]
},
{
"_id": "63123af290530000860042b2",
...
"meetings": [
]
},
{
"_id": "63123b0c90530000860042b5",
...
"meetings": [
]
}
]
without using take(), all the related meeting documents are loaded.
i'm using jenssegers-mongodb package for laravel-mongodb connection, but the issue also occurs on vanilla eloquent.