Priority to rules with a scenario

Hi,

To avoid having to define a scenario to all rules, i suggest that Yii ignores generic rules and takes those with a scenario if the corresponding scenario is found.

example:




public function rules() {

        return array(

            array('name','file','allowEmpty'=>false),

            array('name','required','on'=>'update'),

        );

}



In that case, even if i use:


$this->model->setScenario('update');

I’ll get a validation error:

[color="#FF0000"]Name cannot be blank.[/color]

To avoid this i have to define a new scenario like this:




public function rules() {

        return array(

            array('name','file','on'=>'save','allowEmpty'=>false),

            array('name','required','on'=>'update'),

        );

}



But it’s really borring…

This should be an automatic priority.

oops i just fixed some rules in the code example.

This is now more corresponding to my problem

what if you need two or more rules entries to define your attribute rules?

Example:


return array(

    array('login', 'length', 'max'=>30, 'min' => 6),

    array('login', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u'),

    array('login', 'unique', 'message' => 'Please choose another login.', 'on'=>'insert'),

);

Oh, you’re right.

But i suggest at least a new parameter for quickly ignore a rule (eg a ‘skipOn’ parameter).

example:


return array(

    array('login', 'length', 'max'=>30, 'min' => 6,'skipOn'=>'insert'),

    array('login', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u'),

    array('login', 'unique', 'message' => 'Please choose another login.', 'on'=>'insert'),

);

It’s more quick and of course less borring.

+1 to add an ‘ignore’ parameter

I think there would be lots of use cases

Agreed on skipOn parameter, having the same problem >:(