0

这里有没有人使用标准->比较通过模型中的关系将单个输入与 2 个单独的表列进行比较?

这是我的关系声明:

    'class' => array(self::HAS_ONE, 'BaseEiEquipItem', 'iar_no'),
    'classSi' => array(self::HAS_ONE, 'BaseSiReceivedItem','iar_no'),

现在我想比较我的输入是否存在于这两个表中

    if(!empty($_GET['BaseIar']['description'])){
        $this->description= $_GET['BaseIar']['description'];
        $criteria->with = array('class','classSi');//this will serve as join
        $criteria->compare('class.description,classSi.description', $this->description, true ); // true is equivalence of like %%
    }
    else{
        $this->description='';
        $criteria->with = array('class','classSi' );//this will serve as join
        $criteria->compare('class.description,classSi.description', $this->description, true ); // true is equivalence of like %%
    }
4

2 回答 2

0

为什么你一次又一次地重复相同的代码尝试使用三元运算符试试这个

$this->description = (!empty($_GET['BaseIar']['description'])) ? $_GET['BaseIar']['description'] : '';
$criteria->with = array(
                    'class' => array(
                      'condition' => "class.description LIKE :desc"
                      'params' => array(":desc" => "%{$this->description}%")
                    ),
                    'classSi' => array(
                      'condition' => "classSi.description LIKE :desc"
                      'params' => array(":desc" => "%{$this->description}%")
                    ));
于 2013-09-13T05:24:34.787 回答
0

你可以试试这样的

$criteria->compare('class.description', $this->description, true);
$criteria->compare('classSi.description', $this->description, true, 'OR');
于 2013-09-13T09:47:13.883 回答