PHP 클래스 EMongoDocument, MongoYii

The active record itself
상속: extends EMongoModel
파일 보기 프로젝트 열기: sammaye/mongoyii 1 사용 예제들

공개 메소드들

메소드 설명
__call ( string $name, array $parameters ) : EMongoDocument | mixed This, in addition to EMongoModels edition, will also call scopes on the model
__construct ( string $scenario = 'insert' ) Sets up our model and set the field cache just like in EMongoModel
aggregate ( array $pipeline ) : mixed This is an aggregate helper on the model Note: This does not return the model but instead the result array directly from MongoDB.
cache ( integer $duration, CCacheDependency | ICacheDependency $dependency = null, integer $queryCount = 1 ) : EMongoDocument Sets the parameters for query caching.
collectionName ( ) : string Returns the collection name as a string
count ( EMongoCriteria | array $criteria = [] ) : integer Count() allows you to count all the documents returned by a certain condition, it is analogous to $db->collection->find()->count() and basically does exactly that.
defaultScope ( ) : array Sets the default scope
delete ( ) : boolean Deletes this record
deleteAll ( array | EMongoCriteria $criteria = [], array $options = [] ) : mixed Delete all records matching a criteria
deleteByPk ( string | MongoId $pk, array | EMongoCriteria $criteria = [], array $options = [] ) : mixed Delete record by pk
distinct ( string $key, array $query = [] ) : mixed A distinct helper on the model, this is not the same as the aggregation framework distinct
ensureIndexes ( unknown $indexes ) Allows a user to ensure a number of indexes using the format:
equals ( EMongoDocument $record ) : boolean Compares current active record with another one.
exists ( array $criteria = [] ) : boolean Checks if a record exists in the database
find ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Find some records
findAll ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Alias of find
findAllByAttributes ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Alias of find
findAllByPk ( mixed $pk, array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Finds all records based on $pk
findAndModify ( $criteria = [], $updateDoc = [], $fields = [], $options = [] ) : null | EMongoDocument Find one record, modifies, and returns it.
findByPk ( string | MongoId $pk, array | string[] $fields = [] ) : EMongoDocument | null An alias for findBy_id() that relates to Yiis own findByPk
findBy_id ( string | MongoId $_id, array | string[] $fields = [] ) : EMongoDocument | null Finds one by _id
findOne ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoDocument | null Find one record
getAttributeLabel ( string $attribute ) : string Returns the text label for the specified attribute.
getCollection ( ) : MongoCollection Gets the collection for this model
getDbCriteria ( boolean $createIfNull = true ) : array gets and if null sets the db criteria for this model
getIsNewRecord ( ) : boolean Returns if the current record is new.
getLastError ( ) : array A bit deceptive, this actually gets the last response from either save() or update(). The reason it is called this is because MongoDB calls it this and so it seems better to have unity on that front.
getLatest ( ) : null | EMongoDocument Is basically a find one of the last version to be saved
getMongoId ( string | MongoId $value = null ) : MongoId Returns MongoId based on $value
getPrimaryKey ( string | MongoId $value = null ) : MongoId Returns the value of the primary key
getProjectedFields ( ) : array | string[] Gets a list of the projected fields for the model
incrementVersion ( ) : boolean Forceably increments the version of this document
insert ( array $attributes = null ) : boolean Inserts this record
mapreduce ( MongoCode $map, MongoCode $reduce, MongoCode $finalize = null, array $out = [], array $query = [], array $options = [] ) : mixed A mapreduce helper for this model
mergeCriteria ( array $oldCriteria, array $newCriteria ) : array Merges two criteria objects. Best used for scopes
mergeDbCriteria ( array | EMongoCriteria $newCriteria ) : array Merges the current DB Criteria with the inputted one
model ( string $className = __CLASS__ ) : EMongoDocument Returns the static model of the specified AR class.
onAfterDelete ( CEvent $event )
onAfterFind ( CEvent $event )
onAfterSave ( CEvent $event )
onBeforeDelete ( CEvent $event )
onBeforeFind ( CEvent $event )
onBeforeSave ( CEvent $event )
populateRecord ( array $attributes, boolean $callAfterFind = true, boolean $partial = false ) : EMongoDocument | null Creates an active record with the given attributes.
populateRecords ( array $data, boolean $callAfterFind = true, string $index = null ) : array Returns an array of records populated by incoming data
refresh ( ) : boolean Refreshes the data from the database
resetScope ( boolean $resetDefault = true ) : EMongoDocument Resets the scopes applied to the model clearing the _criteria variable
save ( boolean $runValidation = true, array $attributes = null ) : boolean Saves this record
saveAttributes ( array $attributes ) : boolean Saves only a specific subset of attributes as defined by the param
saveCounters ( array $counters, null $lower = null, null $upper = null ) : boolean
scopes ( ) : array The scope attached to this model
search ( array $query = [], array $project = [], boolean $partialMatch = false, array $sort = [] ) : EMongoDataProvider Gives basic searching abilities for things like CGridView
setAttribute ( string $name, mixed $value ) : boolean Sets the attribute of the model
setDbCriteria ( array $criteria ) : array Sets the db criteria for this model
setIsNewRecord ( boolean $value ) Sets if the record is new.
setProjectedFields ( array $fields ) Sets the projected fields of the model
setVersion ( mixed $n ) : boolean Forceably sets the version of this document
trace ( string $func ) Produces a trace message for functions in this class
update ( array $attributes = null ) : boolean Updates this record
updateAll ( array | EMongoCriteria $criteria = [], array $updateDoc = [], array $options = ['multiple' => true] ) : boolean Update all records matching a criteria
updateByPk ( string | MongoId $pk, array $updateDoc = [], array | EMongoCriteria $criteria = [], array $options = [] ) : boolean Update record by PK
version ( ) : string Gets the version of this document
versionField ( ) : string Denotes the field tob e used to house the version number
versioned ( ) : boolean Denotes whether or not this document is versioned

보호된 메소드들

메소드 설명
afterDelete ( )
afterFind ( )
afterSave ( )
beforeDelete ( ) : boolean
beforeFind ( )
beforeSave ( ) : boolean
instantiate ( array $document ) : EMongoDocument Instantiates a model from an array

메소드 상세

__call() 공개 메소드

This, in addition to EMongoModels edition, will also call scopes on the model
또한 보기: EMongoModel::__call()
public __call ( string $name, array $parameters ) : EMongoDocument | mixed
$name string
$parameters array
리턴 EMongoDocument | mixed

__construct() 공개 메소드

It will also set the default scope on the model so be aware that if you want the default scope to not be applied you will need to run resetScope() straight after making this model
public __construct ( string $scenario = 'insert' )
$scenario string

afterDelete() 보호된 메소드

protected afterDelete ( )

afterFind() 보호된 메소드

protected afterFind ( )

afterSave() 보호된 메소드

protected afterSave ( )

aggregate() 공개 메소드

This is an aggregate helper on the model Note: This does not return the model but instead the result array directly from MongoDB.
public aggregate ( array $pipeline ) : mixed
$pipeline array
리턴 mixed

beforeDelete() 보호된 메소드

protected beforeDelete ( ) : boolean
리턴 boolean

beforeFind() 보호된 메소드

protected beforeFind ( )

beforeSave() 보호된 메소드

protected beforeSave ( ) : boolean
리턴 boolean

cache() 공개 메소드

This is a shortcut method to {@link CDbConnection::cache()}. It changes the query caching parameter of the {@link dbConnection} instance.
public cache ( integer $duration, CCacheDependency | ICacheDependency $dependency = null, integer $queryCount = 1 ) : EMongoDocument
$duration integer the number of seconds that query results may remain valid in cache. If this is 0, the caching will be disabled.
$dependency CCacheDependency | ICacheDependency the dependency that will be used when saving the query results into cache.
$queryCount integer number of MongoDB queries that need to be cached after calling this method. Defaults to 1, meaning that the next MongoDB query will be cached.
리턴 EMongoDocument the active record instance itself.

collectionName() 공개 메소드

Returns the collection name as a string
public collectionName ( ) : string
리턴 string

count() 공개 메소드

..
public count ( EMongoCriteria | array $criteria = [] ) : integer
$criteria EMongoCriteria | array
리턴 integer

defaultScope() 공개 메소드

Sets the default scope
public defaultScope ( ) : array
리턴 array - An array which represents a single scope within the scope() function

delete() 공개 메소드

Deletes this record
public delete ( ) : boolean
리턴 boolean

deleteAll() 공개 메소드

Delete all records matching a criteria
public deleteAll ( array | EMongoCriteria $criteria = [], array $options = [] ) : mixed
$criteria array | EMongoCriteria
$options array
리턴 mixed

deleteByPk() 공개 메소드

Delete record by pk
public deleteByPk ( string | MongoId $pk, array | EMongoCriteria $criteria = [], array $options = [] ) : mixed
$pk string | MongoId
$criteria array | EMongoCriteria
$options array
리턴 mixed

distinct() 공개 메소드

A distinct helper on the model, this is not the same as the aggregation framework distinct
public distinct ( string $key, array $query = [] ) : mixed
$key string
$query array
리턴 mixed

ensureIndexes() 공개 메소드

ensureIndexes(array( array(array('email' => 1), array('unique' => true)) )) where the 0 offset in each nested array is the fields for the index and the 1 offset is the options. You don't have to define options for the index. or: ensureIndexes(array( array('email' => 1, 'address' => -1) ))
public ensureIndexes ( unknown $indexes )
$indexes unknown

equals() 공개 메소드

The comparison is made by comparing table name and the primary key values of the two active records.
public equals ( EMongoDocument $record ) : boolean
$record EMongoDocument - record to compare to
리턴 boolean - whether the two active records refer to the same row in the database table.

exists() 공개 메소드

Checks if a record exists in the database
public exists ( array $criteria = [] ) : boolean
$criteria array
리턴 boolean

find() 공개 메소드

Find some records
public find ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array | EMongoCriteria
$fields array | string[]
리턴 EMongoCursor | EMongoDocument[]

findAll() 공개 메소드

Alias of find
public findAll ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array
$fields array | string[]
리턴 EMongoCursor | EMongoDocument[]

findAllByAttributes() 공개 메소드

Alias of find
public findAllByAttributes ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array
$fields array | string[]
리턴 EMongoCursor | EMongoDocument[]

findAllByPk() 공개 메소드

Finds all records based on $pk
public findAllByPk ( mixed $pk, array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$pk mixed - String, MongoID or array of strings or MongoID values (one can mix strings and MongoID in the array)
$fields array | string[]
리턴 EMongoCursor | EMongoDocument[]

findAndModify() 공개 메소드

Find one record, modifies, and returns it.
public findAndModify ( $criteria = [], $updateDoc = [], $fields = [], $options = [] ) : null | EMongoDocument
리턴 null | EMongoDocument

findByPk() 공개 메소드

An alias for findBy_id() that relates to Yiis own findByPk
public findByPk ( string | MongoId $pk, array | string[] $fields = [] ) : EMongoDocument | null
$pk string | MongoId
$fields array | string[]
리턴 EMongoDocument | null

findBy_id() 공개 메소드

Finds one by _id
public findBy_id ( string | MongoId $_id, array | string[] $fields = [] ) : EMongoDocument | null
$_id string | MongoId
$fields array | string[]
리턴 EMongoDocument | null

findOne() 공개 메소드

Find one record
public findOne ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoDocument | null
$criteria array | EMongoCriteria
$fields array | string[]
리턴 EMongoDocument | null

getAttributeLabel() 공개 메소드

This method overrides the parent implementation by supporting returning the label defined in relational object. In particular, if the attribute name is in the form of "post.author.name", then this method will derive the label from the "author" relation's "name" attribute.
또한 보기: CModel::generateAttributeLabel()
public getAttributeLabel ( string $attribute ) : string
$attribute string - the attribute name
리턴 string - the attribute label

getCollection() 공개 메소드

Gets the collection for this model
public getCollection ( ) : MongoCollection
리턴 MongoCollection

getDbCriteria() 공개 메소드

gets and if null sets the db criteria for this model
public getDbCriteria ( boolean $createIfNull = true ) : array
$createIfNull boolean
리턴 array

getIsNewRecord() 공개 메소드

Whether the record is new and should be inserted when calling {@link save}. This property is automatically set in constructor and {@link populateRecord}. Defaults to false, but it will be set to true if the instance is created using the new operator.
public getIsNewRecord ( ) : boolean
리턴 boolean

getLastError() 공개 메소드

A bit deceptive, this actually gets the last response from either save() or update(). The reason it is called this is because MongoDB calls it this and so it seems better to have unity on that front.
public getLastError ( ) : array
리턴 array

getLatest() 공개 메소드

Is basically a find one of the last version to be saved
public getLatest ( ) : null | EMongoDocument
리턴 null | EMongoDocument

getMongoId() 공개 메소드

Returns MongoId based on $value
사용 중단: This function will become deprecated in favour of consistently using the getPrimaryKey() function instead. Atm, however, the getPrimaryKey function actually chains onto this method. If you see this and are wondering about what you should do if you want custom primary keys etc just use the getPrimaryKey function as you would the getMongoId function. These two functions should never have been separate for they are the same essentially. As to what version this will become deprecated:- I dunno. It will not be soon since it will be a functionality breaker...
public getMongoId ( string | MongoId $value = null ) : MongoId
$value string | MongoId
리턴 MongoId

getPrimaryKey() 공개 메소드

Returns the value of the primary key
public getPrimaryKey ( string | MongoId $value = null ) : MongoId
$value string | MongoId
리턴 MongoId

getProjectedFields() 공개 메소드

Gets a list of the projected fields for the model
public getProjectedFields ( ) : array | string[]
리턴 array | string[]

incrementVersion() 공개 메소드

Forceably increments the version of this document
public incrementVersion ( ) : boolean
리턴 boolean

insert() 공개 메소드

Inserts this record
public insert ( array $attributes = null ) : boolean
$attributes array
리턴 boolean

instantiate() 보호된 메소드

Instantiates a model from an array
protected instantiate ( array $document ) : EMongoDocument
$document array
리턴 EMongoDocument

mapreduce() 공개 메소드

A mapreduce helper for this model
public mapreduce ( MongoCode $map, MongoCode $reduce, MongoCode $finalize = null, array $out = [], array $query = [], array $options = [] ) : mixed
$map MongoCode
$reduce MongoCode
$finalize MongoCode
$out array
$query array
$options array // All other options for input to the command
리턴 mixed

mergeCriteria() 공개 메소드

Merges two criteria objects. Best used for scopes
public mergeCriteria ( array $oldCriteria, array $newCriteria ) : array
$oldCriteria array
$newCriteria array
리턴 array

mergeDbCriteria() 공개 메소드

Merges the current DB Criteria with the inputted one
public mergeDbCriteria ( array | EMongoCriteria $newCriteria ) : array
$newCriteria array | EMongoCriteria
리턴 array

model() 공개 정적인 메소드

The model returned is a static instance of the AR class. It is provided for invoking class-level methods (something similar to static class methods.) EVERY derived AR class must override this method as follows,
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
public static model ( string $className = __CLASS__ ) : EMongoDocument
$className string
리턴 EMongoDocument

onAfterDelete() 공개 메소드

public onAfterDelete ( CEvent $event )
$event CEvent

onAfterFind() 공개 메소드

public onAfterFind ( CEvent $event )
$event CEvent

onAfterSave() 공개 메소드

public onAfterSave ( CEvent $event )
$event CEvent

onBeforeDelete() 공개 메소드

public onBeforeDelete ( CEvent $event )
$event CEvent

onBeforeFind() 공개 메소드

public onBeforeFind ( CEvent $event )
$event CEvent

onBeforeSave() 공개 메소드

public onBeforeSave ( CEvent $event )
$event CEvent

populateRecord() 공개 메소드

This method is internally used by the find methods. Null is returned if the input data is false.
public populateRecord ( array $attributes, boolean $callAfterFind = true, boolean $partial = false ) : EMongoDocument | null
$attributes array - attribute values (column name=>column value)
$callAfterFind boolean whether to call {@link afterFind} after the record is populated.
$partial boolean
리턴 EMongoDocument | null - the newly created active record. The class of the object is the same as the model class.

populateRecords() 공개 메소드

Returns an array of records populated by incoming data
public populateRecords ( array $data, boolean $callAfterFind = true, string $index = null ) : array
$data array
$callAfterFind boolean
$index string
리턴 array - Array of the records

refresh() 공개 메소드

Refreshes the data from the database
public refresh ( ) : boolean
리턴 boolean

resetScope() 공개 메소드

Resets the scopes applied to the model clearing the _criteria variable
public resetScope ( boolean $resetDefault = true ) : EMongoDocument
$resetDefault boolean
리턴 EMongoDocument

save() 공개 메소드

If an attributes specification is sent in it will only validate and save those attributes
public save ( boolean $runValidation = true, array $attributes = null ) : boolean
$runValidation boolean
$attributes array
리턴 boolean

saveAttributes() 공개 메소드

Saves only a specific subset of attributes as defined by the param
public saveAttributes ( array $attributes ) : boolean
$attributes array
리턴 boolean

saveCounters() 공개 메소드

또한 보기: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveCounters-detail
public saveCounters ( array $counters, null $lower = null, null $upper = null ) : boolean
$counters array
$lower null - define a lower that the counter should not pass. IS NOT ATOMIC
$upper null
리턴 boolean

scopes() 공개 메소드

It is very much like how Yii normally uses scopes except the params are slightly different.
public scopes ( ) : array
리턴 array

setAttribute() 공개 메소드

Sets the attribute of the model
public setAttribute ( string $name, mixed $value ) : boolean
$name string
$value mixed
리턴 boolean

setDbCriteria() 공개 메소드

Sets the db criteria for this model
public setDbCriteria ( array $criteria ) : array
$criteria array
리턴 array

setIsNewRecord() 공개 메소드

Whether the record is new and should be inserted when calling {@link save}.
또한 보기: EMongoDocument::getIsNewRecord()
public setIsNewRecord ( boolean $value )
$value boolean

setProjectedFields() 공개 메소드

Sets the projected fields of the model
public setProjectedFields ( array $fields )
$fields array

setVersion() 공개 메소드

Forceably sets the version of this document
public setVersion ( mixed $n ) : boolean
$n mixed
리턴 boolean

trace() 공개 메소드

Produces a trace message for functions in this class
public trace ( string $func )
$func string

update() 공개 메소드

Updates this record
public update ( array $attributes = null ) : boolean
$attributes array
리턴 boolean

updateAll() 공개 메소드

Update all records matching a criteria
public updateAll ( array | EMongoCriteria $criteria = [], array $updateDoc = [], array $options = ['multiple' => true] ) : boolean
$criteria array | EMongoCriteria
$updateDoc array
$options array
리턴 boolean

updateByPk() 공개 메소드

Update record by PK
public updateByPk ( string | MongoId $pk, array $updateDoc = [], array | EMongoCriteria $criteria = [], array $options = [] ) : boolean
$pk string | MongoId
$updateDoc array
$criteria array | EMongoCriteria
$options array
리턴 boolean

version() 공개 메소드

Gets the version of this document
public version ( ) : string
리턴 string

versionField() 공개 메소드

Denotes the field tob e used to house the version number
public versionField ( ) : string
리턴 string

versioned() 공개 메소드

Denotes whether or not this document is versioned
public versioned ( ) : boolean
리턴 boolean