Yii标准 - 修改为包含OR条件

时间:2015-06-03 09:57:11

标签: mysql yii yii-components

我有以下代码行执行简单查询

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)

1 个答案:

答案 0 :(得分:3)

尝试类似的东西

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

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