New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation rules issues when using model's attribute as additional parameters #3001
Comments
Not an issue. This is by design. Treat |
If this is the understanding about it at least it should be well documented. Using protected attributes instead of private, or setter/getters for all vars, would allow a more flexible usage of the framework. A resetValidators() { $this->_validators = null; } method would do the trick too. All that need to be done is set CModel->_validators = null before validation. |
Maybe it worth documenting it. The
The problem is that if we'll use this way lazy validators initiation would become meaningless. |
I guess a better solution would be to use evaluateExpression() on validator's parameters |
As CModel._validators = CModel.createValidators() is called before any model's attribute be setted, the validation rules are compiled with attributes's default values.
This could lead to validation issues. To avoid that, CModel.validate() should always compile validation rules on runtime.
This is best observable when using CUniqueValidato, e.g.:
In this example, CModel._validators will contain a CUniqueValidator validation rule
with :someAttr setted as NULL. CModel.validate() will always return TRUE regardless of MyModel->uniqueAttr 's value, since there isn't any AnotherClass->notNullAttr == NULL.
The text was updated successfully, but these errors were encountered: