$query = Doctrine_Query::create()
->select('IF(m.sender_id = ?, m.receiver_id, m.sender_id) AS uid', $my_id)
->from('Message m')
->where('m.receiver_id = ? OR m.sender_id = ?', array($my_id,$my_id))
->groupBy('uid')
I am unable to group by 'uid', as if AS uid is not working at all...
If I try to retrieve generated sql via ->getSqlQuery() and try it directly in Mysql, it works.
SELECT IF(s.sender_id = 1, s.receiver_i开发者_如何转开发d, s.sender_id) AS s__0
FROM message s
WHERE (s.receiver_id = 1 OR s.sender_id = 1) GROUP BY s__0
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder();
$q = $qb
->select("c.id")
->addSelect("CASE WHEN (c.parent IS NULL) THEN c.name ELSE 'something' END")
->from("MyBundle:Category", "c")
->leftJoin("c.parent", "t");
echo $q->getQuery()->getSQL();
精彩评论