Laravel ORM "with" is returning all rows even with constraint
Using Laravel 4 Eloquent ORM, any idea why the following is pulling every
row instead of just the one I'm asking for (book_id=3)?
if ($Book = Book::find($id)) {
return ($Book::with(array('chapters.pages' => function($query)
{
$query->where('book_id', '=', 3 ); // hard-coded
id for illustration purposes
})
)->get()->toJson());
}
The output I'm getting is every single book with every chapter and every
page. I only want to pull that single book with chapters and pages.
According to the documentation I should be able to add a constraint. Seems
like I'm following the docs pretty closely. Thanks in advance.
No comments:
Post a Comment