PHP Class Mongolid\ActiveRecord

The Mongolid\Schema\Schema that describes the entity will be generated on the go based on the $fields.
Inheritance: implements Mongolid\Model\AttributesAccessInterface, implements Mongolid\Schema\HasSchemaInterface, use trait Mongolid\Model\Attributes, use trait Mongolid\Model\Relations
Mostrar archivo Open project: leroy-merlin-br/mongolid Class Usage Examples

Public Properties

Property Type Description
$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 Properties

Property Type Description
$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

Public Methods

Method Description
__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.

Protected Methods

Method Description
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.

Private Methods

Method Description
getDataMapperInstance ( ) : mixed Returns the a valid instance from Ioc.

Method Details

__call() public method

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.
return mixed

all() public static method

Gets a cursor of this kind of entities from the database.
public static all ( ) : Cursor
return Mongolid\Cursor\Cursor

delete() public method

Deletes this object in database.
public delete ( ) : boolean
return boolean Success

execute() protected method

Performs the given action into database.
protected execute ( string $action ) : boolean
$action string Datamapper function to execute.
return boolean

first() public static method

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.
return ActiveRecord

firstOrFail() public static method

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.
return ActiveRecord

firstOrNew() public static method

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.
return ActiveRecord

getCollectionName() public method

Getter for the $collection attribute.
public getCollectionName ( ) : string
return string

getDataMapper() public method

Returns a DataMapper configured with the Schema and collection described in this entity.
public getDataMapper ( ) : DataMapper
return Mongolid\DataMapper\DataMapper

getSchema() public method

public getSchema ( ) : Schema
return Mongolid\Schema\Schema

getWriteConcern() public method

Getter for $writeConcern variable.
public getWriteConcern ( ) : mixed
return mixed

insert() public method

Insert this object into database.
public insert ( ) : boolean
return boolean Success

instantiateSchemaInFields() protected method

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
return Mongolid\Schema\Schema | null

save() public method

Saves this object into database.
public save ( ) : boolean
return boolean Success

setWriteConcern() public method

Setter for $writeConcern variable.
public setWriteConcern ( mixed $writeConcern ) : void
$writeConcern mixed Level of write concern to the transation.
return void

update() public method

Updates this object in database.
public update ( ) : boolean
return boolean Success

where() public static method

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.
return Mongolid\Cursor\Cursor

Property Details

$collection protected_oe property

Name of the collection where this kind of Entity is going to be saved or retrieved from.
protected string $collection
return string

$dynamic public_oe property

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
return boolean

$fields protected_oe property

Describes the Schema fields of the model. Optionally you can set it to the name of a Schema class to be used.
See also: Mongolid\Schema\Schema::$fields
protected string|string[] $fields
return string | string[]

$writeConcern protected_oe property

See also: https://docs.mongodb.com/manual/reference/write-concern/
protected int $writeConcern
return integer