Yii2: Why yii\base\Model::getActiveValidators($attribute) don`t return validator, if i add '!' as prefix to attribute name in rules.

Created on 28 Nov 2016  路  1Comment  路  Source: yiisoft/yii2

if i add next to rules:

[['!coinsImage'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],

i will exclude it from massive assignment, but can`t get that validator when use:

$model->getActiveValidators('coinsImage');

I think next condition wrong:

if ($validator->isActive($scenario) && ($attribute === null || in_array($attribute, $validator->attributes, true))) {
                $validators[] = $validator;
            }

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.10

to be verified bug

Most helpful comment

Workaround:
$model->getActiveValidators('!coinsImage');
but it is not obvious.
You can find a proper fix in my PR #13088

>All comments

Workaround:
$model->getActiveValidators('!coinsImage');
but it is not obvious.
You can find a proper fix in my PR #13088

Was this page helpful?
0 / 5 - 0 ratings