phpDataMapper icon indicating copy to clipboard operation
phpDataMapper copied to clipboard

N+1 query problem

Open JeromeDane opened this issue 13 years ago • 0 comments

From relationships documentation:

"Currently, the above ‘HasMany’ example will incur N+1 queries. That is, one query will be executed for each set of comments requested for each post. So if 20 posts are returned and you print the comments for all posts, 20+1 queries will be executed."

I'm going to take a stab at this in my fork so that only two queries are generated as described. I'm thinking of implementing some version of the $authorMapper->select()->with('books')->where(...) syntax used in phpActiveRecord as described here and here (eager loading)

JeromeDane avatar Mar 09 '11 15:03 JeromeDane