johnnietheblack
johnnietheblack

Reputation: 13320

How to effecient execute a more complex Doctrine 2 lazy load?

Let's say I have a User entity and a Comments entity, with a relationship of one-to-many.

Let's also say that I am using Doctrine 2 to pull my User entity from the DB, and I am opting to lazy-load my user's comments, vs pull everything all at once.

I now have a specific page where I want to show the user's last comment, and upon asking the User for it's comments, the lazy-loading proxy kicks in and pulls the comments from the database.

This is where my problem starts: for most people who have 1-5 comments, this is fine...however, if the person has hundreds or thousands of comments, how do I use lazy-loading when I don't want to load all the comments at once?

Is this beyond Doctrine 2?

Upvotes: 0

Views: 173

Answers (1)

Jani Hartikainen
Jani Hartikainen

Reputation: 43243

The lazy loading mechanism is only capable of loading the full set. In order to only load the last one you would need to use a DQL query.

Upvotes: 1

Related Questions