public updateAttributes ( array $attributes ) : integer | ||
$attributes | array | the attributes (names or name-value pairs) to be updated |
return | integer | the number of rows affected. |
public function updateAttributes($attributes)
{
$attrs = [];
foreach ($attributes as $name => $value) {
if (is_int($name)) {
$attrs[] = $value;
} else {
$this->{$name} = $value;
$attrs[] = $name;
}
}
$values = $this->getDirtyAttributes($attrs);
if (empty($values) || $this->getIsNewRecord()) {
return 0;
}
$rows = static::updateAll($values, $this->getOldPrimaryKey(true));
foreach ($values as $name => $value) {
$this->_oldAttributes[$name] = $this->_attributes[$name];
}
return $rows;
}