2

我遇到了以下问题。我只想显示插入任务本身或负责任务的人的任务,为此,我有以下数据库模式:

table Funcionario (员工表) = id, name, etc...

表 TarefasGerais(任务表)= id,id_funcionario(谁插入它)等...

table TarefasResponsaveis(负责员工表)= id,id_tarefa(tarefas gerais id),id_funcionario(员工id)

在我模型的搜索方法中,我执行了以下操作:

    $criteria->with = array('Responsaveis' => 
        array('condition' => 'Responsaveis.id_funcionario = ' . Yii::app()->user->dados->id));
    $criteria->condition = 'id_funcionario_lancamento = ' . Yii::app()->user->dados->id;

但它会生成以下 SQL:

    SELECT COUNT(DISTINCT `t`.`id`) FROM `tbl_tarefas_gerais` `t` LEFT OUTER JOIN `tbl_tarefas_gerais_responsaveis` `Responsaveis` ON
    (`Responsaveis`.`id_tarefa` = `t`.`id`) WHERE (id_funcionario_lancamento =
    3) AND (Responsaveis.id_funcionario = 3)

如您所见,它使用“AND”运算符,但我需要它在 where 部分使用“OR”运算符。

我试过了 :

    $criteria->with = array('Responsaveis' =>
        array('condition' => 'Responsaveis.id_funcionario = ' . Yii::app()->user->dados->id, 'operator' => 'OR'));

但它没有改变任何东西。

有谁知道如何处理?

干杯 0/

4

1 回答 1

5

尝试mergeWith两个标准。

将您的逻辑分解为两个标准并将它们合并在一起

$criteria->with = array('Responsaveis' => 
    array('condition' => 'Responsaveis.id_funcionario = ' . Yii::app()->user->dados->id));
$criteria2->condition = 'id_funcionario_lancamento = ' . Yii::app()->user->dados->id;
$criteria->mergeWith($criteria2);

完整示例:

$criteria2 = new CDbCriteria();
$criteria2->addInCondition('startDate', array(null));
$criteria2->addBetweenCondition('startDate', date('Y-m-d'), '1950-01-01', 'OR');

$criteria3 = new CDbCriteria();
$criteria3->addInCondition('stopDate', array(null), 'AND');
$criteria3->addBetweenCondition('stopDate', '1990-01-01', date('Y-m-d'), 'OR');

$criteria3->mergeWith($criteria2);
于 2013-03-14T16:47:31.070 回答