嗨,学说2中有ifnull吗?我需要使用...如何?
SELECT *
FROM `apns_task_message`
ORDER BY IFNULL( `sent_at` , NOW( ) ) , `priority` DESC , `position` ASC
如何将此 sql 转换为学说?
$qb = $this->getRepository()->createQueryBuilder('tm');
$qb->leftJoin('tm.apnsTask', 't');
$qb->add('where', 't.id = :task_id')->setParameter('task_id', $task_id);
//$qb->add('orderBy', 'IFNULL(tm.sent_at, NOW()), tm.priority DESC, tm.position ASC');
$qb->add('orderBy', 'd_date, tm.priority DESC, tm.position ASC');
$q = $qb->getQuery();
return $q->getResult();
成立!!!感谢@AdrienBrault 的“coalesce”运营商
$now = new \DateTime("now");
$qb = $this->getRepository()->createQueryBuilder('tm');
$qb->addSelect('coalesce (tm.sentAt, :sent_date) as sent_date')->setParameter('sent_date', $now->format("Y-m-d H:i:s"));
$qb->leftJoin('tm.apnsTask', 't');
$qb->add('where', 't.id = :task_id')->setParameter('task_id', $task_id);
$qb->add('orderBy', 'sent_date ASC, tm.priority DESC, tm.position ASC');
$q = $qb->getQuery();