Monday, August 29, 2011

Example of Including 'criteria' with a Unique Validation Rule


public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('entity_category_id, entity_id', 'required'),
array('preferred','boolean'),

                        // unique with condition
array('preferred','unique',
'criteria'=>array(
'condition'=>'entity_id=:entity_id',
'params'=>array(':entity_id'=>$this->entity_id),
),
),

// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, entity_category_id, entity_id', 'safe', 'on'=>'search'),
);
}

No comments:

Post a Comment