elieandraos's avatar

Eager Loading + Restriction + Pagination

I have a small application on Laravel 5.1 that has a polymorphic relations. So in a certain part of the app, I have a "Title' that is themable.

I am trying to get all titles belonging to specific themes (tags) based on the theme ids.

I am using eager loading to get the list, but the problem is that the query is returning all the titles.

Example code:

$titles = Title::with(['themes'=>function($query){
            $query->whereIn('id',[8]);
        }])->paginate(10)

I would expect the code above to put in "titles" only the titles that have themes and where the theme id is 8.

But it is actually returning all the titles with themes (everything in the database). But it only loads the themes with id = 8 This is messing up the pagination.

Am I doing something wrong?

0 likes
0 replies

Please or to participate in this conversation.