Skip to content

Commit 4010723

Browse files
committed
docs: update docs
1 parent 756ebfe commit 4010723

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

user_guide_src/source/models/model.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,25 @@ $skipValidation
191191
---------------
192192

193193
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
195195
primarily used by the ``skipValidation()`` method, but may be changed to ``true`` so
196196
this model will never validate.
197197

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+
198213
$beforeInsert
199214
-------------
200215
$afterInsert
@@ -392,9 +407,12 @@ For many people, validating data in the model is the preferred way to ensure the
392407
standard, without duplicating code. The Model class provides a way to automatically have all data validated
393408
prior to saving to the database with the ``insert()``, ``update()``, or ``save()`` methods.
394409

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.
398416

399417
The first step is to fill out the ``$validationRules`` class property with the fields and rules that should
400418
be applied. If you have custom error message that you want to use, place them in the ``$validationMessages`` array:

0 commit comments

Comments
 (0)