symfony2 doctrine select IFNULL

馋奶兔 提交于 2019-12-05 00:57:30

Use COALESCE instead of IFNULL like this

$fields = array('COALESCE(s2.id,s1.id) AS effectiveID','COALESCE(s2.status, s1.status) AS effectiveStatus', 'COALESCE(s2.user_id, s1.user_id) as effectiveUser','COALESCE(s2.likes_count, s1.likes_count) as effectiveLikesCount');

COALESCE return the first value not null in the list, so if A is null and B not null, then COALESCE(A,B) will return B.

Philipp

There is a Doctrine extension that adds this among others.

This is the DQL file from IFNULL. https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/IfNull.php

This chapter explains how you use them. http://symfony.com/doc/2.0/cookbook/doctrine/custom_dql_functions.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!