Cake\ORM\Table::_update PHP Method

_update() protected method

Auxiliary function to handle the update of an entity's data in the table
protected _update ( Cake\Datasource\EntityInterface $entity, array $data ) : Cake\Datasource\EntityInterface | boolean
$entity Cake\Datasource\EntityInterface the subject entity from were $data was extracted
$data array The actual data that needs to be saved
return Cake\Datasource\EntityInterface | boolean
    protected function _update($entity, $data)
    {
        $primaryColumns = (array) $this->primaryKey();
        $primaryKey = $entity->extract($primaryColumns);
        $data = array_diff_key($data, $primaryKey);
        if (empty($data)) {
            return $entity;
        }
        if (!$entity->has($primaryColumns)) {
            $message = 'All primary key value(s) are needed for updating, ';
            $message .= get_class($entity) . ' is missing ' . implode(', ', $primaryColumns);
            throw new InvalidArgumentException($message);
        }
        $query = $this->query();
        $statement = $query->update()->set($data)->where($primaryKey)->execute();
        $success = false;
        if ($statement->errorCode() === '00000') {
            $success = $entity;
        }
        $statement->closeCursor();
        return $success;
    }