如何在doctrine 2查询中选择set columns

时间:2015-01-08 09:08:31

标签: doctrine-orm

下面是我的学说2查询。它有效。

对我来说唯一的问题是它会抽出每个表中的所有列:这是不必要的开销

我只想从每个表中选择某些列;我尝试从每个表中选择几列,但查询中断了。

    $qb  =  $this->queryBuilder()
                   ->select(array('u','ph','st'))
                   ->from('BaseModel\Entity\User','u')
                   ->leftJoin('u.statementObject','st')
                   ->leftJoin('u.thePhotoObject','ph')  
      $query = $qb->getQuery();

        $users = $query->getArrayResult();

,即我只想从用户表中选择名称,因此查询应如下所示:

    $qb  =  $this->queryBuilder()
                   ->select(array('u.name','u.name','ph.photoOne','st'))
                   ->from('BaseModel\Entity\User','u')
                   ->leftJoin('u.statementObject','st')
                   ->leftJoin('u.thePhotoObject','ph')  
      $query = $qb->getQuery();

        $users = $query->getArrayResult();

1 个答案:

答案 0 :(得分:0)

 $qb = $this->queryBuilder()
           ->select('u.name, ph.photoOne')
           ->from('BaseModel\Entity\User','u')
           ->leftJoin('u.statementObject','st')
           ->leftJoin('u.thePhotoObject','ph')  
 $query = $qb->getQuery();

 $users = $query->getArrayResult();