我有下面一行代码,用于执行一个简单的查询

if ($this->fulfilled)
   $criteria->addCondition('fulfilled ' . (($this->fulfilled == 1) ? "IS NOT NULL" : "IS NULL"));

如何修改它以执行包含OR命令的查询,以便基本上使用框架而不是原始SQL运行此查询
if ($this->fulfilled)
AND (fulfilled is null OR fulfilled = 0)

最佳答案

试试那样的东西

 $criteriaOr = new CDbCriteria();
    $criteriaOr->addCondition('fulfilled IS NULL', 'OR');
    $criteriaOr->addCondition('fulfilled = 0', 'OR');

然后if($this->fulfielled) {$criteria->mergeWith($criteriaOr);}

关于mysql - Yii条件-修改为包含OR条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30616772/

10-14 14:42