douguangxiang0363 2015-01-15 13:46
浏览 72

带有join的Doctrine查询构建器返回实体数组而不是分组结果

I have some problems with Doctrine. Im trying to do a leftJoin, following this question: How to do left join in Doctrine?

Here is my query:

$qb = $this->getEntityManager()->createQueryBuilder();
    $qb
        ->select('a', 'u')
        ->from('Application\Entity\Event', 'a')
        ->leftJoin(
            'Application\Entity\Venue',
            'u',
            \Doctrine\ORM\Query\Expr\Join::WITH,
            'a.venue_id = u.id'
        )
        ->orderBy('a.event_datetime', 'DESC');

    var_dump($qb->getQuery()->getResult());

And here are the results:

array (size=4)
0 => 
object(Application\Entity\Event)[483]
  protected 'id' => int 8
  protected 'artist_id' => int 4
  protected 'venue_id' => int 1246
  protected 'name' => string 'Vlasta Redl' (length=11)
1 => 
object(Application\Entity\Venue)[477]
  protected 'id' => int 1246
  protected 'name' => string 'Malostranská beseda' (length=20)
  ...
2 => 
object(Application\Entity\Event)[468]
  protected 'id' => int 7
  protected 'artist_id' => int 3
  protected 'venue_id' => int 761
  protected 'name' => string 'Positive Mind' (length=13)

3 => 
object(Application\Entity\Venue)[485]
  protected 'id' => int 761
  protected 'name' => string 'Divadlo pod lampou' (length=18)
  ....

This is an array of different objects. Events and Venues.

But I'm expecting such result:

array(
    array(
        0 => Event
        1 => Venue,
    ),
    array(
        0 => Event
        1 => Venue,
    ),
    // ...
)

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • doutang7415 2015-01-15 14:01
    关注

    I tried but I could not.

    I have done so:

    foreach($result as $object){
                if(get_class($object)=='Panel\PollBundle\Entity\PollProfile'){
                    $pollProfile[] = $object;
                }
                else if (get_class($object)=='Panel\PollBundle\Entity\Poll') {
                    $poll[] = $object;
                }
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示