baibaratsky / yii2-serialized-attributes-behavior

ActiveRecord behavior that allows you to store arrays in attributes
Other
11 stars 7 forks source link

You could add a Validator #5

Closed robsch closed 7 years ago

robsch commented 7 years ago

It would be nice if one could also specify a special rule four such fields. Now I have to use safe for such fields.

E.g.:

public function rules() {
    return [
        [['my_field'], 'serialized', 'max' => 10000],
    ];
}

With max it could be checked that the string won't get truncated.

baibaratsky commented 7 years ago

Often you need to serialize an attribute not from the POST, so validation rules are not the place to configure serialization. Also, I think it’s not good idea to check length of serialized data using validation rules. These rules are for user‘s input validation, not for internal constraints checking.

robsch commented 7 years ago

Okay, I see and I think you're right.