PHP Класс yii\mongodb\ActiveRecord

С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\db\BaseActiveRecord
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
attributes ( ) : array Returns the list of all attribute names of the model.
collectionName ( ) : string | array Declares the name of the Mongo collection associated with this AR class.
delete ( ) : integer | boolean Deletes the document corresponding to this active record from the collection.
deleteAll ( array $condition = [], array $options = [] ) : integer Deletes documents in the collection using the provided conditions.
equals ( ActiveRecord $record ) : boolean Returns a value indicating whether the given active record is the same as the current one.
find ( ) : ActiveQuery
getCollection ( ) : Collection Return the Mongo collection instance for this AR class.
getDb ( ) : Connection Returns the Mongo connection used by this AR class.
insert ( boolean $runValidation = true, array $attributes = null ) : boolean Inserts a row into the associated Mongo collection using the attribute values of this record.
primaryKey ( ) : string[] Returns the primary key name(s) for this AR class.
toArray ( array $fields = [], array $expand = [], $recursive = true )
updateAll ( array $attributes, array $condition = [], array $options = [] ) : integer Updates all documents in the collection using the provided attribute values and conditions.
updateAllCounters ( array $counters, array $condition = [], array $options = [] ) : integer Updates all documents in the collection using the provided counter changes and conditions.

Защищенные методы

Метод Описание
deleteInternal ( )
insertInternal ( $attributes = null )
updateInternal ( $attributes = null )

Приватные методы

Метод Описание
dumpBsonObject ( MongoDB\BSON\Type $object ) : array | string Converts MongoDB BSON object to readable value.
toArrayInternal ( mixed $data ) : array Converts data to array recursively, converting MongoDB BSON objects to readable values.

Описание методов

attributes() публичный Метод

This method must be overridden by child classes to define available attributes. Note: primary key attribute "_id" should be always present in returned array. For example: php public function attributes() { return ['_id', 'name', 'address', 'status']; }
public attributes ( ) : array
Результат array list of attribute names.

collectionName() публичный статический Метод

Collection name can be either a string or array: - if string considered as the name of the collection inside the default database. - if array - first element considered as the name of the database, second - as name of collection inside that database By default this method returns the class name as the collection name by calling [[Inflector::camel2id()]]. For example, 'Customer' becomes 'customer', and 'OrderItem' becomes 'order_item'. You may override this method if the collection is not named after this convention.
public static collectionName ( ) : string | array
Результат string | array the collection name

delete() публичный Метод

This method performs the following steps in order: 1. call [[beforeDelete()]]. If the method returns false, it will skip the rest of the steps; 2. delete the document from the collection; 3. call [[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 | boolean
Результат integer | boolean the number of documents deleted, or false if the deletion is unsuccessful for some reason. Note that it is possible the number of documents deleted is 0, even though the deletion execution is successful.

deleteAll() публичный статический Метод

WARNING: If you do not specify any condition, this method will delete documents rows in the collection. For example, to delete all customers whose status is 3: php Customer::deleteAll(['status' => 3]);
public static deleteAll ( array $condition = [], array $options = [] ) : integer
$condition array description of the objects to delete. Please refer to [[Query::where()]] on how to specify this parameter.
$options array list of options in format: optionName => optionValue.
Результат integer the number of documents deleted.

deleteInternal() защищенный Метод

См. также: ActiveRecord::delete()
protected deleteInternal ( )

equals() публичный Метод

The comparison is made by comparing the collection 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 ( ActiveRecord $record ) : boolean
$record ActiveRecord record to compare to
Результат boolean whether the two active records refer to the same row in the same Mongo collection.

find() публичный статический Метод

public static find ( ) : ActiveQuery
Результат ActiveQuery the newly created [[ActiveQuery]] instance.

getCollection() публичный статический Метод

Return the Mongo collection instance for this AR class.
public static getCollection ( ) : Collection
Результат Collection collection instance.

getDb() публичный статический Метод

By default, the "mongodb" application component is used as the Mongo connection. You may override this method if you want to use a different database connection.
public static getDb ( ) : Connection
Результат Connection the database connection used by this AR class.

insert() публичный Метод

This method performs the following steps in order: 1. call [[beforeValidate()]] when $runValidation is true. If validation fails, it will skip the rest of the steps; 2. call [[afterValidate()]] when $runValidation is true. 3. call [[beforeSave()]]. If the method returns false, it will skip the rest of the steps; 4. insert the record into collection. If this fails, it will skip the rest of the steps; 5. call [[afterSave()]]; In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]], [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]] will be raised by the corresponding methods. Only the [[dirtyAttributes|changed attribute values]] will be inserted into database. If the primary key is null during insertion, it will be populated with the actual value after insertion. For example, to insert a customer record: php $customer = new Customer(); $customer->name = $name; $customer->email = $email; $customer->insert();
public insert ( boolean $runValidation = true, array $attributes = null ) : boolean
$runValidation boolean whether to perform validation before saving the record. If the validation fails, the record will not be inserted into the collection.
$attributes array list of attributes that need to be saved. Defaults to null, meaning all attributes that are loaded will be saved.
Результат boolean whether the attributes are valid and the record is inserted successfully.

insertInternal() защищенный Метод

См. также: ActiveRecord::insert()
protected insertInternal ( $attributes = null )

primaryKey() публичный статический Метод

The default implementation will return ['_id']. Note that an array should be returned even for a collection with single primary key.
public static primaryKey ( ) : string[]
Результат string[] the primary keys of the associated Mongo collection.

toArray() публичный Метод

public toArray ( array $fields = [], array $expand = [], $recursive = true )
$fields array
$expand array

updateAll() публичный статический Метод

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, array $condition = [], array $options = [] ) : integer
$attributes array attribute values (name-value pairs) to be saved into the collection
$condition array description of the objects to update. Please refer to [[Query::where()]] on how to specify this parameter.
$options array list of options in format: optionName => optionValue.
Результат integer the number of documents updated.

updateAllCounters() публичный статический Метод

For example, to increment all customers' age by 1, php Customer::updateAllCounters(['age' => 1]);
public static updateAllCounters ( array $counters, array $condition = [], array $options = [] ) : integer
$counters array the counters to be updated (attribute name => increment value). Use negative values if you want to decrement the counters.
$condition array description of the objects to update. Please refer to [[Query::where()]] on how to specify this parameter.
$options array list of options in format: optionName => optionValue.
Результат integer the number of documents updated.

updateInternal() защищенный Метод

См. также: ActiveRecord::update()
protected updateInternal ( $attributes = null )