PHP Класс Mongolid\ActiveRecord

The Mongolid\Schema\Schema that describes the entity will be generated on the go based on the $fields.
Наследование: implements Mongolid\Model\AttributesAccessInterface, implements Mongolid\Schema\HasSchemaInterface, use trait Mongolid\Model\Attributes, use trait Mongolid\Model\Relations
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$dynamic boolean The $dynamic property tells if the object will accept additional fields that are not specified in the $fields property. This is useful if you does not have a strict document format or if you want to take full advantage of the "schemaless" nature of MongoDB.

Защищенные свойства (Protected)

Свойство Тип Описание
$collection string Name of the collection where this kind of Entity is going to be saved or retrieved from.
$fields string | string[] Describes the Schema fields of the model. Optionally you can set it to the name of a Schema class to be used.
$writeConcern integer

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

Метод Описание
__call ( mixed $method, mixed $parameters ) : mixed Handle dynamic method calls into the model.
all ( ) : Cursor Gets a cursor of this kind of entities from the database.
delete ( ) : boolean Deletes this object in database.
first ( mixed $query = [], array $projection = [], boolean $useCache = false ) : ActiveRecord Gets the first entity of this kind that matches the query.
firstOrFail ( mixed $query = [], array $projection = [], boolean $useCache = false ) : ActiveRecord Gets the first entity of this kind that matches the query. If no document was found, throws ModelNotFoundException.
firstOrNew ( mixed $id ) : ActiveRecord Gets the first entity of this kind that matches the query. If no document was found, a new entity will be returned with the _if field filled.
getCollectionName ( ) : string Getter for the $collection attribute.
getDataMapper ( ) : DataMapper Returns a DataMapper configured with the Schema and collection described in this entity.
getSchema ( ) : Schema
getWriteConcern ( ) : mixed Getter for $writeConcern variable.
insert ( ) : boolean Insert this object into database.
save ( ) : boolean Saves this object into database.
setWriteConcern ( mixed $writeConcern ) : void Setter for $writeConcern variable.
update ( ) : boolean Updates this object in database.
where ( array $query = [], array $projection = [], boolean $useCache = false ) : Cursor Gets a cursor of this kind of entities that matches the query from the database.

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

Метод Описание
execute ( string $action ) : boolean Performs the given action into database.
instantiateSchemaInFields ( ) : Schema | null Will check if the current value of $fields property is the name of a Schema class and instantiate it if possible.

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

Метод Описание
getDataMapperInstance ( ) : mixed Returns the a valid instance from Ioc.

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

__call() публичный метод

Handle dynamic method calls into the model.
public __call ( mixed $method, mixed $parameters ) : mixed
$method mixed Name of the method that is being called.
$parameters mixed Parameters of $method.
Результат mixed

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

Gets a cursor of this kind of entities from the database.
public static all ( ) : Cursor
Результат Mongolid\Cursor\Cursor

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

Deletes this object in database.
public delete ( ) : boolean
Результат boolean Success

execute() защищенный метод

Performs the given action into database.
protected execute ( string $action ) : boolean
$action string Datamapper function to execute.
Результат boolean

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

Gets the first entity of this kind that matches the query.
public static first ( mixed $query = [], array $projection = [], boolean $useCache = false ) : ActiveRecord
$query mixed MongoDB selection criteria.
$projection array Fields to project in Mongo query.
$useCache boolean Retrieves the entity through a CacheableCursor.
Результат ActiveRecord

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

Gets the first entity of this kind that matches the query. If no document was found, throws ModelNotFoundException.
public static firstOrFail ( mixed $query = [], array $projection = [], boolean $useCache = false ) : ActiveRecord
$query mixed MongoDB selection criteria.
$projection array Fields to project in Mongo query.
$useCache boolean Retrieves the entity through a CacheableCursor.
Результат ActiveRecord

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

Gets the first entity of this kind that matches the query. If no document was found, a new entity will be returned with the _if field filled.
public static firstOrNew ( mixed $id ) : ActiveRecord
$id mixed Document id.
Результат ActiveRecord

getCollectionName() публичный метод

Getter for the $collection attribute.
public getCollectionName ( ) : string
Результат string

getDataMapper() публичный метод

Returns a DataMapper configured with the Schema and collection described in this entity.
public getDataMapper ( ) : DataMapper
Результат Mongolid\DataMapper\DataMapper

getSchema() публичный метод

public getSchema ( ) : Schema
Результат Mongolid\Schema\Schema

getWriteConcern() публичный метод

Getter for $writeConcern variable.
public getWriteConcern ( ) : mixed
Результат mixed

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

Insert this object into database.
public insert ( ) : boolean
Результат boolean Success

instantiateSchemaInFields() защищенный метод

Will check if the current value of $fields property is the name of a Schema class and instantiate it if possible.
protected instantiateSchemaInFields ( ) : Schema | null
Результат Mongolid\Schema\Schema | null

save() публичный метод

Saves this object into database.
public save ( ) : boolean
Результат boolean Success

setWriteConcern() публичный метод

Setter for $writeConcern variable.
public setWriteConcern ( mixed $writeConcern ) : void
$writeConcern mixed Level of write concern to the transation.
Результат void

update() публичный метод

Updates this object in database.
public update ( ) : boolean
Результат boolean Success

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

Gets a cursor of this kind of entities that matches the query from the database.
public static where ( array $query = [], array $projection = [], boolean $useCache = false ) : Cursor
$query array MongoDB selection criteria.
$projection array Fields to project in Mongo query.
$useCache boolean Retrieves a CacheableCursor instead.
Результат Mongolid\Cursor\Cursor

Описание свойств

$collection защищенное свойство

Name of the collection where this kind of Entity is going to be saved or retrieved from.
protected string $collection
Результат string

$dynamic публичное свойство

The $dynamic property tells if the object will accept additional fields that are not specified in the $fields property. This is useful if you does not have a strict document format or if you want to take full advantage of the "schemaless" nature of MongoDB.
public bool $dynamic
Результат boolean

$fields защищенное свойство

Describes the Schema fields of the model. Optionally you can set it to the name of a Schema class to be used.
См. также: Mongolid\Schema\Schema::$fields
protected string|string[] $fields
Результат string | string[]

$writeConcern защищенное свойство

См. также: https://docs.mongodb.com/manual/reference/write-concern/
protected int $writeConcern
Результат integer