PHP Class yii\db\BaseActiveRecord

See ActiveRecord for a concrete implementation.
Since: 2.0
Author: Qiang Xue ([email protected])
Author: Carsten Brandt ([email protected])
Inheritance: extends yii\base\Model, implements yii\db\ActiveRecordInterface
Datei anzeigen Open project: yiisoft/yii2 Class Usage Examples

Public Methods

Method Description
__get ( string $name ) : mixed PHP getter magic method.
__isset ( string $name ) : boolean Checks if a property value is null.
__set ( string $name, mixed $value ) PHP setter magic method.
__unset ( string $name ) Sets a component property to be null.
afterDelete ( ) This method is invoked after deleting a record.
afterFind ( ) This method is called when the AR object is created and populated with the query result.
afterRefresh ( ) This method is called when the AR object is refreshed.
afterSave ( boolean $insert, array $changedAttributes ) This method is called at the end of inserting or updating a record.
beforeDelete ( ) : boolean This method is invoked before deleting a record.
beforeSave ( boolean $insert ) : boolean This method is called at the beginning of inserting or updating a record.
canGetProperty ( $name, $checkVars = true, $checkBehaviors = true )
canSetProperty ( $name, $checkVars = true, $checkBehaviors = true )
delete ( ) : integer | false Deletes the table row corresponding to this active record.
deleteAll ( string | array $condition = '', array $params = [] ) : integer Deletes rows in the table using the provided conditions.
equals ( yii\db\ActiveRecordInterface $record ) : boolean Returns a value indicating whether the given active record is the same as the current one.
extraFields ( )
fields ( )
findAll ( $condition ) : static[]
findOne ( $condition ) : static
getAttribute ( string $name ) : mixed Returns the named attribute value.
getAttributeHint ( string $attribute ) : string Returns the text hint for the specified attribute.
getAttributeLabel ( string $attribute ) : string Returns the text label for the specified attribute.
getDirtyAttributes ( string[] | null $names = null ) : array Returns the attribute values that have been modified since they are loaded or saved most recently.
getIsNewRecord ( ) : boolean Returns a value indicating whether the current record is new.
getOldAttribute ( string $name ) : mixed Returns the old value of the named attribute.
getOldAttributes ( ) : array Returns the old attribute values.
getOldPrimaryKey ( boolean $asArray = false ) : mixed Returns the old primary key value(s).
getPrimaryKey ( boolean $asArray = false ) : mixed Returns the primary key value(s).
getRelatedRecords ( ) : array Returns all populated related records.
getRelation ( string $name, boolean $throwException = true ) : yii\db\ActiveQueryInterface | ActiveQuery Returns the relation object with the specified name.
hasAttribute ( string $name ) : boolean Returns a value indicating whether the model has an attribute with the specified name.
hasMany ( string $class, array $link ) : yii\db\ActiveQueryInterface Declares a has-many relation.
hasOne ( string $class, array $link ) : yii\db\ActiveQueryInterface Declares a has-one relation.
init ( ) Initializes the object.
instantiate ( array $row ) : static Creates an active record instance.
isAttributeChanged ( string $name, boolean $identical = true ) : boolean Returns a value indicating whether the named attribute has been changed.
isPrimaryKey ( array $keys ) : boolean Returns a value indicating whether the given set of attributes represents the primary key for this model
isRelationPopulated ( string $name ) : boolean Check whether the named relation has been populated with records.
link ( string $name, yii\db\ActiveRecordInterface $model, array $extraColumns = [] ) Establishes the relationship between two models.
markAttributeDirty ( string $name ) Marks an attribute dirty.
offsetExists ( mixed $offset ) : boolean Returns whether there is an element at the specified offset.
offsetUnset ( mixed $offset ) Sets the element value at the specified offset to null.
optimisticLock ( ) : string Returns the name of the column that stores the lock version for implementing optimistic locking.
populateRecord ( BaseActiveRecord $record, array $row ) Populates an active record object using a row of data from the database/storage.
populateRelation ( string $name, yii\db\ActiveRecordInterface | array | null $records ) Populates the named relation with the related records.
refresh ( ) : boolean Repopulates this active record with the latest data.
save ( boolean $runValidation = true, array $attributeNames = null ) : boolean Saves the current record.
setAttribute ( string $name, mixed $value ) Sets the named attribute value.
setIsNewRecord ( boolean $value ) Sets the value indicating whether the record is new.
setOldAttribute ( string $name, mixed $value ) Sets the old value of the named attribute.
setOldAttributes ( array | null $values ) Sets the old attribute values.
unlink ( string $name, yii\db\ActiveRecordInterface $model, boolean $delete = false ) Destroys the relationship between two models.
unlinkAll ( string $name, boolean $delete = false ) Destroys the relationship in current model.
update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false Saves the changes to this active record into the associated database table.
updateAll ( array $attributes, string | array $condition = '' ) : integer Updates the whole table using the provided attribute values and conditions.
updateAllCounters ( array $counters, string | array $condition = '' ) : integer Updates the whole table using the provided counter changes and conditions.
updateAttributes ( array $attributes ) : integer Updates the specified attributes.
updateCounters ( array $counters ) : boolean Updates one or several counter columns for the current AR object.

Protected Methods

Method Description
findByCondition ( mixed $condition ) : yii\db\ActiveQueryInterface Finds ActiveRecord instance(s) by the given condition.
updateInternal ( array $attributes = null ) : integer | false

Private Methods

Method Description
bindModels ( array $link, yii\db\ActiveRecordInterface $foreignModel, yii\db\ActiveRecordInterface $primaryModel )

Method Details

__get() public method

This method is overridden so that attributes and related objects can be accessed like properties.
See also: getAttribute()
public __get ( string $name ) : mixed
$name string property name
return mixed property value

__isset() public method

This method overrides the parent implementation by checking if the named attribute is null or not.
public __isset ( string $name ) : boolean
$name string the property name or the event name
return boolean whether the property value is null

__set() public method

This method is overridden so that AR attributes can be accessed like properties.
public __set ( string $name, mixed $value )
$name string property name
$value mixed property value

__unset() public method

This method overrides the parent implementation by clearing the specified attribute value.
public __unset ( string $name )
$name string the property name or the event name

afterDelete() public method

The default implementation raises the [[EVENT_AFTER_DELETE]] event. You may override this method to do postprocessing after the record is deleted. Make sure you call the parent implementation so that the event is raised properly.
public afterDelete ( )

afterFind() public method

The default implementation will trigger an [[EVENT_AFTER_FIND]] event. When overriding this method, make sure you call the parent implementation to ensure the event is triggered.
public afterFind ( )

afterRefresh() public method

The default implementation will trigger an [[EVENT_AFTER_REFRESH]] event. When overriding this method, make sure you call the parent implementation to ensure the event is triggered.
Since: 2.0.8
public afterRefresh ( )

afterSave() public method

The default implementation will trigger an [[EVENT_AFTER_INSERT]] event when $insert is true, or an [[EVENT_AFTER_UPDATE]] event if $insert is false. The event class used is [[AfterSaveEvent]]. When overriding this method, make sure you call the parent implementation so that the event is triggered.
public afterSave ( boolean $insert, array $changedAttributes )
$insert boolean whether this method called while inserting a record. If `false`, it means the method is called while updating a record.
$changedAttributes array The old values of attributes that had changed and were saved. You can use this parameter to take action based on the changes made for example send an email when the password had changed or implement audit trail that tracks all the changes. `$changedAttributes` gives you the old attribute values while the active record (`$this`) has already the new, updated values. Note that no automatic type conversion performed by default. You may use [[\yii\behaviors\AttributeTypecastBehavior]] to facilitate attribute typecasting. See http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#attributes-typecasting.

beforeDelete() public method

The default implementation raises the [[EVENT_BEFORE_DELETE]] event. When overriding this method, make sure you call the parent implementation like the following: php public function beforeDelete() { if (parent::beforeDelete()) { ...custom code here... return true; } else { return false; } }
public beforeDelete ( ) : boolean
return boolean whether the record should be deleted. Defaults to `true`.

beforeSave() public method

The default implementation will trigger an [[EVENT_BEFORE_INSERT]] event when $insert is true, or an [[EVENT_BEFORE_UPDATE]] event if $insert is false. When overriding this method, make sure you call the parent implementation like the following: php public function beforeSave($insert) { if (parent::beforeSave($insert)) { ...custom code here... return true; } else { return false; } }
public beforeSave ( boolean $insert ) : boolean
$insert boolean whether this method called while inserting a record. If `false`, it means the method is called while updating a record.
return boolean whether the insertion or updating should continue. If `false`, the insertion or updating will be cancelled.

canGetProperty() public method

public canGetProperty ( $name, $checkVars = true, $checkBehaviors = true )

canSetProperty() public method

public canSetProperty ( $name, $checkVars = true, $checkBehaviors = true )

delete() public method

This method performs the following steps in order: 1. call BaseActiveRecord::beforeDelete. If the method returns false, it will skip the rest of the steps; 2. delete the record from the database; 3. call BaseActiveRecord::afterDelete. In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]] will be raised by the corresponding methods.
public delete ( ) : integer | false
return integer | false the number of rows deleted, or `false` if the deletion is unsuccessful for some reason. Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.

deleteAll() public static method

WARNING: If you do not specify any condition, this method will delete ALL rows in the table. For example, to delete all customers whose status is 3: php Customer::deleteAll('status = 3');
public static deleteAll ( string | array $condition = '', array $params = [] ) : integer
$condition string | array the conditions that will be put in the WHERE part of the DELETE SQL. Please refer to [[Query::where()]] on how to specify this parameter.
$params array the parameters (name => value) to be bound to the query.
return integer the number of rows deleted

equals() public method

The comparison is made by comparing the table names and the primary key values of the two active records. If one of the records [[isNewRecord|is new]] they are also considered not equal.
public equals ( yii\db\ActiveRecordInterface $record ) : boolean
$record yii\db\ActiveRecordInterface record to compare to
return boolean whether the two active records refer to the same row in the same database table.

extraFields() public method

public extraFields ( )

fields() public method

public fields ( )

findAll() public static method

public static findAll ( $condition ) : static[]
return static[] an array of ActiveRecord instances, or an empty array if nothing matches.

findByCondition() protected static method

This method is internally called by BaseActiveRecord::findOne and BaseActiveRecord::findAll.
protected static findByCondition ( mixed $condition ) : yii\db\ActiveQueryInterface
$condition mixed please refer to [[findOne()]] for the explanation of this parameter
return yii\db\ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.

findOne() public static method

public static findOne ( $condition ) : static
return static ActiveRecord instance matching the condition, or `null` if nothing matches.

getAttribute() public method

If this record is the result of a query and the attribute is not loaded, null will be returned.
See also: hasAttribute()
public getAttribute ( string $name ) : mixed
$name string the attribute name
return mixed the attribute value. `null` if the attribute is not set or does not exist.

getAttributeHint() public method

If the attribute looks like relatedModel.attribute, then the attribute will be received from the related model.
See also: attributeHints()
Since: 2.0.4
public getAttributeHint ( string $attribute ) : string
$attribute string the attribute name
return string the attribute hint

getAttributeLabel() public method

If the attribute looks like relatedModel.attribute, then the attribute will be received from the related model.
See also: generateAttributeLabel()
See also: attributeLabels()
public getAttributeLabel ( string $attribute ) : string
$attribute string the attribute name
return string the attribute label

getDirtyAttributes() public method

The comparison of new and old values is made for identical values using ===.
public getDirtyAttributes ( string[] | null $names = null ) : array
$names string[] | null the names of the attributes whose values may be returned if they are changed recently. If null, [[attributes()]] will be used.
return array the changed attribute values (name-value pairs)

getIsNewRecord() public method

Returns a value indicating whether the current record is new.
public getIsNewRecord ( ) : boolean
return boolean whether the record is new and should be inserted when calling [[save()]].

getOldAttribute() public method

If this record is the result of a query and the attribute is not loaded, null will be returned.
See also: hasAttribute()
public getOldAttribute ( string $name ) : mixed
$name string the attribute name
return mixed the old attribute value. `null` if the attribute is not loaded before or does not exist.

getOldAttributes() public method

Returns the old attribute values.
public getOldAttributes ( ) : array
return array the old attribute values (name-value pairs)

getOldPrimaryKey() public method

This refers to the primary key value that is populated into the record after executing a find method (e.g. find(), findOne()). The value remains unchanged even if the primary key attribute is manually assigned with a different value.
public getOldPrimaryKey ( boolean $asArray = false ) : mixed
$asArray boolean whether to return the primary key value as an array. If `true`, the return value will be an array with column name as key and column value as value. If this is `false` (default), a scalar value will be returned for non-composite primary key.
return mixed the old primary key value. An array (column name => column value) is returned if the primary key is composite or `$asArray` is `true`. A string is returned otherwise (null will be returned if the key value is null).

getPrimaryKey() public method

Returns the primary key value(s).
public getPrimaryKey ( boolean $asArray = false ) : mixed
$asArray boolean whether to return the primary key value as an array. If `true`, the return value will be an array with column names as keys and column values as values. Note that for composite primary keys, an array will always be returned regardless of this parameter value.
return mixed the primary key value. An array (column name => column value) is returned if the primary key is composite or `$asArray` is `true`. A string is returned otherwise (null will be returned if the key value is null).

getRelatedRecords() public method

Returns all populated related records.
See also: getRelation()
public getRelatedRecords ( ) : array
return array an array of related records indexed by relation names.

getRelation() public method

A relation is defined by a getter method which returns an ActiveQueryInterface object. It can be declared in either the Active Record class itself or one of its behaviors.
public getRelation ( string $name, boolean $throwException = true ) : yii\db\ActiveQueryInterface | ActiveQuery
$name string the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive).
$throwException boolean whether to throw exception if the relation does not exist.
return yii\db\ActiveQueryInterface | ActiveQuery the relational query object. If the relation does not exist and `$throwException` is `false`, `null` will be returned.

hasAttribute() public method

Returns a value indicating whether the model has an attribute with the specified name.
public hasAttribute ( string $name ) : boolean
$name string the name of the attribute
return boolean whether the model has an attribute with the specified name.

hasMany() public method

The declaration is returned in terms of a relational ActiveQuery instance through which the related record can be queried and retrieved back. A has-many relation means that there are multiple related records matching the criteria set by this relation, e.g., a customer has many orders. For example, to declare the orders relation for Customer class, we can write the following code in the Customer class: php public function getOrders() { return $this->hasMany(Order::className(), ['customer_id' => 'id']); } Note that in the above, the 'customer_id' key in the $link parameter refers to an attribute name in the related class Order, while the 'id' value refers to an attribute name in the current AR class. Call methods declared in ActiveQuery to further customize the relation.
public hasMany ( string $class, array $link ) : yii\db\ActiveQueryInterface
$class string the class name of the related record
$link array the primary-foreign key constraint. The keys of the array refer to the attributes of the record associated with the `$class` model, while the values of the array refer to the corresponding attributes in **this** AR class.
return yii\db\ActiveQueryInterface the relational query object.

hasOne() public method

The declaration is returned in terms of a relational ActiveQuery instance through which the related record can be queried and retrieved back. A has-one relation means that there is at most one related record matching the criteria set by this relation, e.g., a customer has one country. For example, to declare the country relation for Customer class, we can write the following code in the Customer class: php public function getCountry() { return $this->hasOne(Country::className(), ['id' => 'country_id']); } Note that in the above, the 'id' key in the $link parameter refers to an attribute name in the related class Country, while the 'country_id' value refers to an attribute name in the current AR class. Call methods declared in ActiveQuery to further customize the relation.
public hasOne ( string $class, array $link ) : yii\db\ActiveQueryInterface
$class string the class name of the related record
$link array the primary-foreign key constraint. The keys of the array refer to the attributes of the record associated with the `$class` model, while the values of the array refer to the corresponding attributes in **this** AR class.
return yii\db\ActiveQueryInterface the relational query object.

init() public method

This method is called at the end of the constructor. The default implementation will trigger an [[EVENT_INIT]] event. If you override this method, make sure you call the parent implementation at the end to ensure triggering of the event.
public init ( )

instantiate() public static method

This method is called together with BaseActiveRecord::populateRecord by ActiveQuery. It is not meant to be used for creating new records directly. You may override this method if the instance being created depends on the row data to be populated into the record. For example, by creating a record based on the value of a column, you may implement the so-called single-table inheritance mapping.
public static instantiate ( array $row ) : static
$row array row data to be populated into the record.
return static the newly created active record

isAttributeChanged() public method

Returns a value indicating whether the named attribute has been changed.
public isAttributeChanged ( string $name, boolean $identical = true ) : boolean
$name string the name of the attribute.
$identical boolean whether the comparison of new and old value is made for identical values using `===`, defaults to `true`. Otherwise `==` is used for comparison. This parameter is available since version 2.0.4.
return boolean whether the attribute has been changed

isPrimaryKey() public static method

Returns a value indicating whether the given set of attributes represents the primary key for this model
public static isPrimaryKey ( array $keys ) : boolean
$keys array the set of attributes to check
return boolean whether the given set of attributes represents the primary key for this model

isRelationPopulated() public method

Check whether the named relation has been populated with records.
See also: getRelation()
public isRelationPopulated ( string $name ) : boolean
$name string the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive).
return boolean whether relation has been populated with records.

markAttributeDirty() public method

This method may be called to force updating a record when calling BaseActiveRecord::update, even if there is no change being made to the record.
public markAttributeDirty ( string $name )
$name string the attribute name

offsetExists() public method

This method is required by the interface [[\ArrayAccess]].
public offsetExists ( mixed $offset ) : boolean
$offset mixed the offset to check on
return boolean whether there is an element at the specified offset.

offsetUnset() public method

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like unset($model[$offset]).
public offsetUnset ( mixed $offset )
$offset mixed the offset to unset element

optimisticLock() public method

Optimistic locking allows multiple users to access the same record for edits and avoids potential conflicts. In case when a user attempts to save the record upon some staled data (because another user has modified the data), a [[StaleObjectException]] exception will be thrown, and the update or deletion is skipped. Optimistic locking is only supported by BaseActiveRecord::update and BaseActiveRecord::delete. To use Optimistic locking: 1. Create a column to store the version number of each row. The column type should be BIGINT DEFAULT 0. Override this method to return the name of this column. 2. Add a required validation rule for the version column to ensure the version value is submitted. 3. In the Web form that collects the user input, add a hidden field that stores the lock version of the recording being updated. 4. In the controller action that does the data updating, try to catch the [[StaleObjectException]] and implement necessary business logic (e.g. merging the changes, prompting stated data) to resolve the conflict.
public optimisticLock ( ) : string
return string the column name that stores the lock version of a table row. If `null` is returned (default implemented), optimistic locking will not be supported.

populateRecord() public static method

This is an internal method meant to be called to create active record objects after fetching data from the database. It is mainly used by ActiveQuery to populate the query results into active records. When calling this method manually you should call BaseActiveRecord::afterFind on the created record to trigger the [[EVENT_AFTER_FIND|afterFind Event]].
public static populateRecord ( BaseActiveRecord $record, array $row )
$record BaseActiveRecord the record to be populated. In most cases this will be an instance created by [[instantiate()]] beforehand.
$row array attribute values (name => value)

populateRelation() public method

Note that this method does not check if the relation exists or not.
See also: getRelation()
public populateRelation ( string $name, yii\db\ActiveRecordInterface | array | null $records )
$name string the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive).
$records yii\db\ActiveRecordInterface | array | null the related records to be populated into the relation.

refresh() public method

If the refresh is successful, an [[EVENT_AFTER_REFRESH]] event will be triggered. This event is available since version 2.0.8.
public refresh ( ) : boolean
return boolean whether the row still exists in the database. If `true`, the latest data will be populated to this active record. Otherwise, this record will remain unchanged.

save() public method

This method will call [[insert()]] when [[isNewRecord]] is true, or BaseActiveRecord::update when [[isNewRecord]] is false. For example, to save a customer record: php $customer = new Customer; // or $customer = Customer::findOne($id); $customer->name = $name; $customer->email = $email; $customer->save();
public save ( boolean $runValidation = true, array $attributeNames = null ) : boolean
$runValidation boolean whether to perform validation (calling [[validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`.
$attributeNames array list of attribute names that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved.
return boolean whether the saving succeeded (i.e. no validation errors occurred).

setAttribute() public method

Sets the named attribute value.
See also: hasAttribute()
public setAttribute ( string $name, mixed $value )
$name string the attribute name
$value mixed the attribute value.

setIsNewRecord() public method

Sets the value indicating whether the record is new.
See also: getIsNewRecord()
public setIsNewRecord ( boolean $value )
$value boolean whether the record is new and should be inserted when calling [[save()]].

setOldAttribute() public method

Sets the old value of the named attribute.
See also: hasAttribute()
public setOldAttribute ( string $name, mixed $value )
$name string the attribute name
$value mixed the old attribute value.

setOldAttributes() public method

All existing old attribute values will be discarded.
public setOldAttributes ( array | null $values )
$values array | null old attribute values to be set. If set to `null` this record is considered to be [[isNewRecord|new]].

unlinkAll() public method

The model with the foreign key of the relationship will be deleted if $delete is true. Otherwise, the foreign key will be set null and the model will be saved without validation. Note that to destroy the relationship without removing records make sure your keys can be set to null
public unlinkAll ( string $name, boolean $delete = false )
$name string the case sensitive name of the relationship, e.g. `orders` for a relation defined via `getOrders()` method.
$delete boolean whether to delete the model that contains the foreign key.

update() public method

This method performs the following steps in order: 1. call [[beforeValidate()]] when $runValidation is true. If [[beforeValidate()]] returns false, the rest of the steps will be skipped; 2. call [[afterValidate()]] when $runValidation is true. If validation failed, the rest of the steps will be skipped; 3. call BaseActiveRecord::beforeSave. If BaseActiveRecord::beforeSave returns false, the rest of the steps will be skipped; 4. save the record into database. If this fails, it will skip the rest of the steps; 5. call BaseActiveRecord::afterSave; In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]], [[EVENT_AFTER_VALIDATE]], [[EVENT_BEFORE_UPDATE]], and [[EVENT_AFTER_UPDATE]] will be raised by the corresponding methods. Only the [[dirtyAttributes|changed attribute values]] will be saved into database. For example, to update a customer record: php $customer = Customer::findOne($id); $customer->name = $name; $customer->email = $email; $customer->update(); Note that it is possible the update does not affect any row in the table. In this case, this method will return 0. For this reason, you should use the following code to check if update() is successful or not: php if ($customer->update() !== false) { update successful } else { update failed }
public update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false
$runValidation boolean whether to perform validation (calling [[validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`.
$attributeNames array list of attribute names that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved.
return integer | false the number of rows affected, or `false` if validation fails or [[beforeSave()]] stops the updating process.

updateAll() public static method

For example, to change the status to be 1 for all customers whose status is 2: php Customer::updateAll(['status' => 1], 'status = 2');
public static updateAll ( array $attributes, string | array $condition = '' ) : integer
$attributes array attribute values (name-value pairs) to be saved into the table
$condition string | array the conditions that will be put in the WHERE part of the UPDATE SQL. Please refer to [[Query::where()]] on how to specify this parameter.
return integer the number of rows updated

updateAllCounters() public static method

For example, to increment all customers' age by 1, php Customer::updateAllCounters(['age' => 1]);
public static updateAllCounters ( array $counters, string | array $condition = '' ) : integer
$counters array the counters to be updated (attribute name => increment value). Use negative values if you want to decrement the counters.
$condition string | array the conditions that will be put in the WHERE part of the UPDATE SQL. Please refer to [[Query::where()]] on how to specify this parameter.
return integer the number of rows updated

updateAttributes() public method

This method is a shortcut to BaseActiveRecord::update when data validation is not needed and only a small set attributes need to be updated. You may specify the attributes to be updated as name list or name-value pairs. If the latter, the corresponding attribute values will be modified accordingly. The method will then save the specified attributes into database. Note that this method will **not** perform data validation and will **not** trigger events.
public updateAttributes ( array $attributes ) : integer
$attributes array the attributes (names or name-value pairs) to be updated
return integer the number of rows affected.

updateCounters() public method

Note that this method differs from BaseActiveRecord::updateAllCounters in that it only saves counters for the current AR object. An example usage is as follows: php $post = Post::findOne($id); $post->updateCounters(['view_count' => 1]);
See also: updateAllCounters()
public updateCounters ( array $counters ) : boolean
$counters array the counters to be updated (attribute name => increment value) Use negative values if you want to decrement the counters.
return boolean whether the saving is successful

updateInternal() protected method

See also: update()
protected updateInternal ( array $attributes = null ) : integer | false
$attributes array attributes to update
return integer | false the number of rows affected, or false if [[beforeSave()]] stops the updating process.