Bluz\Db\Row::doUpdate PHP Method

doUpdate() protected method

Update row
protected doUpdate ( ) : integer
return integer The number of rows updated
    protected function doUpdate()
    {
        /**
         * Run pre-UPDATE logic
         */
        $this->beforeUpdate();
        $data = $this->toArray();
        /**
         * Execute validator logic
         * Can throw ValidatorException
         */
        $this->assert($data);
        $primaryKey = $this->getPrimaryKey();
        /**
         * Compare the data to the modified fields array to discover
         * which columns have been changed.
         */
        $diffData = array_diff_assoc($data, $this->clean);
        $table = $this->getTable();
        $diffData = $table->filterColumns($diffData);
        /**
         * Execute the UPDATE (this may throw an exception)
         * Do this only if data values were changed.
         * Use the $diffData variable, so the UPDATE statement
         * includes SET terms only for data values that changed.
         */
        if (sizeof($diffData) > 0) {
            $result = $table->update($diffData, $primaryKey);
        } else {
            $result = 0;
        }
        /**
         * Run post-UPDATE logic.  Do this before the _refresh()
         * so the _afterUpdate() function can tell the difference
         * between changed data and clean (pre-changed) data.
         */
        $this->afterUpdate();
        /**
         * Refresh the data just in case triggers in the RDBMS changed
         * any columns.  Also this resets the "clean".
         */
        $this->clean = $this->toArray();
        return $result;
    }