@@ -191,10 +191,25 @@ $skipValidation
191
191
---------------
192
192
193
193
Whether validation should be skipped during all **inserts ** and **updates **. The default
194
- value is false, meaning that data will always attempt to be validated. This is
194
+ value is `` false `` , meaning that data will always attempt to be validated. This is
195
195
primarily used by the ``skipValidation() `` method, but may be changed to ``true `` so
196
196
this model will never validate.
197
197
198
+ .. _clean-validation-rules :
199
+
200
+ $cleanValidationRules
201
+ ---------------------
202
+
203
+ Whether validation rules should be removed that do not exist in the passed data.
204
+ This is used in **updates **.
205
+ The default value is ``true ``, meaning that validation rules for the fields
206
+ that are not present in the passed data will be (temporarily) removed before the validation.
207
+ This is to avoid validation errors when updating only some fields.
208
+
209
+ You can also change the value by the ``cleanRules() `` method.
210
+
211
+ .. note :: Prior to v4.2.7, ``$cleanValidationRules`` did not work due to a bug.
212
+
198
213
$beforeInsert
199
214
-------------
200
215
$afterInsert
@@ -392,9 +407,12 @@ For many people, validating data in the model is the preferred way to ensure the
392
407
standard, without duplicating code. The Model class provides a way to automatically have all data validated
393
408
prior to saving to the database with the ``insert() ``, ``update() ``, or ``save() `` methods.
394
409
395
- .. important :: When you update data, the validation in the model class only validate provided fields.
396
- So when you set the rule ``required ``, if you don't pass the required field data,
397
- the validation won't fail. This is to avoid validation errors when updating only some fields.
410
+ .. important :: When you update data, by default, the validation in the model class only
411
+ validate provided fields. This is to avoid validation errors when updating only some fields.
412
+
413
+ But this means ``required* `` rules do not work as expected when updating.
414
+ If you want to check required fields, you can change the behavior by configuration.
415
+ See :ref: `clean-validation-rules ` for details.
398
416
399
417
The first step is to fill out the ``$validationRules `` class property with the fields and rules that should
400
418
be applied. If you have custom error message that you want to use, place them in the ``$validationMessages `` array:
0 commit comments