Skip to content

Commit 2baa20a

Browse files
committed
Add docs for strictFields
Refs cakephp/cakephp#18324
1 parent a4594d1 commit 2baa20a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

en/appendices/5-3-migration-guide.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ Mailer
113113
- Added ``Message::addAttachment()`` for adding attachments to a message. Like
114114
other message methods, it can be accessed via the ``Mailer`` instance as ``$mailer->addAttachment()``.
115115

116+
ORM
117+
---
118+
119+
- ``Table::patchEntity()``, ``Table::newEntity()``, ``Marshaller::one()`` and
120+
``Marshaller::many()`` now accept a ``strictFields`` option that only applies
121+
validation to the fields listed in the ``fields`` option.
122+
116123
Routing
117124
-------
118125

en/orm/saving-data.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,23 @@ Using this feature is handy when you have many different functions your users
713713
can access and you want to let your users edit different data based on their
714714
privileges.
715715

716+
When using the ``fields`` option, validation will be applied to all fields in
717+
the request data. You can limit validation to only the allowed fields by passing
718+
``strictFields`` to the ``patchEntity()`` or ``newEntity()`` call::
719+
720+
// Contains ['user_id' => 100, 'title' => 'Hacked!'];
721+
$data = $this->request->getData();
722+
723+
// Only title will be validated and updated.
724+
$entity = $this->patchEntity($entity, $data, [
725+
'fields' => ['title'],
726+
'strictFields' => true,
727+
]);
728+
$this->save($entity);
729+
730+
.. versionadded:: 5.3.0
731+
The ``strictFields`` option was added in 5.3.0.
732+
716733
.. _saving-entities:
717734

718735
Saving Entities

0 commit comments

Comments
 (0)