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


i'm trying simple select query subquery in select clause , have not found way it. i've tried both dql , querybuilder, neither work. code follows, please don't use join, simplified example illustrate problem, have legitimate use cases subqueries.

// querybuilder $query = $qb->select(array('a',                             '(select at.addresstypename                                 e:addresstype @                                at.addresstypeid = a.addresstypeid                             ) addresstypename'))             ->from('e:address', 'a')             ->where('a.addressid = :addressid')             ->setparameter('addressid', 1);  // dql $dql = "select a,                 (select at.addresstypename                    e:addresstype @                   at.addresstypeid = a.addresstypeid                ) addresstypename            e:address           a.addressid = :addressid"; $query = $em->createquery($dql)->setparameter(':addressid', 1); 

the following relationship defined on address table:

/**  * @orm\manytoone(targetentity="addresstype")  * @orm\joincolumns({  *   @orm\joincolumn(name="addresstype_id", referencedcolumnname="addresstype_id")  * })  */ protected $addresstype; 

in native sql, query this:

select     a.*,     (         select at.addresstype_name         addresstype @         at.addresstype_id = a.addresstype_id     ) addresstype_name address a.address_id = 1 

any ideas?

$query = $qb->select('a')     ->addselect('(select at.addresstypename             e:addresstype @             at.addresstypeid = a.addresstypeid) addresstypename'         )     ->from('e:address', 'a')     ->where('a.addressid = :addressid')     ->setparameter('addressid', 1); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -