Quantcast
Channel: How to efficiently count related rows within a model using Doctrine2 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to efficiently count related rows within a model using Doctrine2

$
0
0

I'm pretty new to Doctrine and wondering how to efficiently calculate the number of related objects there are for a particular model object.

I read here that it's not a great idea to use the entity manager within models so I'm wondering how I would query the database to find out without lazy loading all of the related models and doing a count().

I haven't really found a great answer yet, but it seems like this is a pretty fundamental thing?

For example

class House{    /**     * @var Room     */    protected $rooms    public function getRoomCount()    {        // Cant use entity manager here?    }}class Room{    // Shed loads of stuff in here}

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images