Yii Active Record搜索不使用默认属性值

时间:2014-05-11 21:18:23

标签: php mysql activerecord yii

我有一个tax表,其中包含以下字段:

tax_id            (tinyint)
tax_chat_type_id  (enum)     default  '0'
tax_min_value     (decimal)  default  0.10
tax_max_value     (decimal)  default  2.00
tax_obs           (varchar)

执行搜索时,search()模型上的Tax方法会$model->search()CGridView上调用以填充表/网格:

public function search()
{
    $sort = new CSort();
    $sort->defaultOrder = 'tax_id DESC';

    $criteria = new CDbCriteria;
    $criteria->compare('tax_id', $this->tax_id, false, 'OR');
    $criteria->compare('tax_chat_type_id', $this->tax_chat_type_id, true, 'OR');
    $criteria->compare('tax_min_value', $this->tax_min_value, true, 'OR');
    $criteria->compare('tax_max_value', $this->tax_max_value, true, 'OR');
    $criteria->compare('tax_obs', $this->tax_obs, true, 'OR');

    return new CActiveDataProvider(
        $this,  Array('criteria' => $criteria, 'sort' => $sort)
    );
}

但是当我修改任何具有默认值的字段的值时,该值的寄存器不会从表/网格中消失。如果我将值返回到默认值,寄存器将返回到表/网格。

发生了什么事?提前谢谢!

修改

var_dump($criteria);返回:

object(CDbCriteria)[89]
     public 'select' => string '*' (length=1)
     public 'distinct' => boolean false
     public 'condition' => string '((tax_chat_type_id LIKE :ycp0) OR (tax_min_value LIKE :ycp1)) OR (tax_max_value LIKE :ycp2)' (length=91)
     public 'params' => 
         array (size=3)
             ':ycp0' => string '%0%' (length=3)
             ':ycp1' => string '%0.10%' (length=6)
             ':ycp2' => string '%2.00%' (length=6)
     public 'limit' => int -1
     public 'offset' => int -1
     public 'order' => string '' (length=0)
     public 'group' => string '' (length=0)
     public 'join' => string '' (length=0)
     public 'having' => string '' (length=0)
     public 'with' => null
     public 'alias' => null
     public 'together' => null
     public 'index' => null
     public 'scopes' => null
     private '_e' (CComponent) => null
     private '_m' (CComponent) => null

0 个答案:

没有答案