Doctrine 2: how do you use a subquery column (in the SELECT clause)

后端 未结 4 1855
天涯浪人
天涯浪人 2020-12-30 00:28

I\'m trying to do a simple select query with a subquery in the SELECT clause and have simply not found a way to do it. I\'ve tried with both DQL and with the QueryBuilder, n

4条回答
  •  情话喂你
    2020-12-30 00:59

    I know this is an old question, but if you want, you could have used another query builder as your subquery:

     $qb->select("a")
                ->addSelect("(" . $qb2->select("at.addresstypeName")
                    ->from("e:Addresstype", "at")
                    ->where("at.addresstypeId = a.addresstypeId")
                    ->getDQL() . ") AS addresstypeName"
                )
                ->from('e:Address', 'a')
                ->where('a.addressId = :addressId')
                ->setParameter('addressId', 1);
    

提交回复
热议问题