Daniel Faria Daniel Faria - 22 days ago 11
PHP Question

Update only one field on Cakephp 3

In some part of my app I need to update only the field

is_active
of some
table
with a lot of fields. What is the best approach to update only this field and avoid the validations and requiriments of all other fields?

Answer

This will work:

$users = TableRegistry::get('Users');
$query = $users->query();
$query->update()
    ->set(['is_active' => true])
    ->where(['id' => $id])
    ->execute();

http://book.cakephp.org/3.0/en/orm/query-builder.html#updating-data

Comments