Symfony 2/Doctrine: How to lower the num of queries without losing the benefit of ORM?

后端 未结 2 1722
悲&欢浪女
悲&欢浪女 2020-12-21 08:48

I\'m using Symfony 2.7 with Doctrine. My controller actions often look like:

# my/namespace/Controller/ItemsController.php          


        
2条回答
  •  忘掉有多难
    2020-12-21 08:54

    As other's have said, you should fetch the group Entities inside your repository. You can use something like this:

    //inside the repository
    public function findAllFetchGroups(){
    
      return $this->createQueryBuilder('a')
        ->addSelect('gs')->join('a.groups', 'gs')
        ->getQuery()->getResult();
    }
    

提交回复
热议问题