Doctrine: Counting an entity's items with a condition

前端 未结 3 1336
说谎
说谎 2021-02-02 10:37

How can I count an entity\'s items with a condition in Doctrine? For example, I realize that I can use:

$usersCount = $dm->getRepository(\'User\')->count()         


        
3条回答
  •  春和景丽
    2021-02-02 11:35

    Since doctrine 2.6 you can just count the result of the provided conditions when you don't really need the data:

    $usersCount = $dm->getRepository('User')->count(array('type' => 'employee'));
    

    Upgrade to 2.6

提交回复
热议问题