yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

Can't use except validator condition

Open glagola opened this issue 11 years ago • 3 comments

Hi!

I'm trying to exclude my validation rules from creation scenario, which name specified in ActiveController::createScenario

Example

public function rules() 
{
    return [
         ['name', 'required', 'except' => 'create'],
    ];
}

As you can see, I have no other rules for 'create' scenario, I'm using the scenario just to exclude validation rule.

But when I call Model::validate() it throws "Unknown scenario" exception.

Where is the bug? In docs or in the code?

glagola avatar Mar 23 '15 16:03 glagola

you could define scenarios yourself to work around this. Model should generate scenarios by also including information from except.

cebe avatar Mar 23 '15 17:03 cebe

@cebe By the way, maybe it is also a bug: If rule has specified no $on, and no $except, it would not be common for all scenarios

glagola avatar Mar 23 '15 20:03 glagola

Resolved by commit a4f760e

klimov-paul avatar Apr 24 '15 15:04 klimov-paul