Table Of Contents

Previous topic

Class Phalcon\Mvc\Model\Exception

Next topic

Class Phalcon\Mvc\Model\Message

This Page

Class Phalcon\Mvc\Model\Manager

implements Phalcon\Mvc\Model\ManagerInterface, Phalcon\DI\InjectionAwareInterface, Phalcon\Events\EventsAwareInterface

This components controls the initialization of models, keeping record of relations between the different models of the application. A ModelsManager is injected to a model via a Dependency Injector Container such as Phalcon\DI.

<?php

 $dependencyInjector = new Phalcon\DI();

 $dependencyInjector->set('modelsManager', function(){
      return new Phalcon\Mvc\Model\Manager();
 });

 $robot = new Robots($dependencyInjector);

Methods

public __construct ()

Phalcon\Mvc\Model\Manager constructor

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the DependencyInjector container

public Phalcon\DiInterface getDI ()

Returns the DependencyInjector container

public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager)

Sets the event manager

public Phalcon\Events\ManagerInterface getEventsManager ()

Returns the internal event manager

public initialize (Phalcon\Mvc\ModelInterface $model)

Initializes a model in the model manager

public bool isInitialized (string $modelName)

Check of a model is already initialized

public Phalcon\Mvc\ModelInterface getLastInitialized ()

Get last initialized model

public Phalcon\Mvc\ModelInterface load (unknown $modelName)

Loads a model throwing an exception if it doesn’t exist

public addHasOne (Phalcon\Mvc\Model $model, mixed $fields, string $referenceModel, mixed $referencedFields, array $options)

Setup a 1-1 relation between two models

public addBelongsTo (Phalcon\Mvc\Model $model, mixed $fields, string $referenceModel, mixed $referencedFields, array $options)

Setup a relation reverse 1-1 between two models

public addHasMany (Phalcon\Mvc\ModelInterface $model, mixed $fields, string $referenceModel, mixed $referencedFields, array $options)

Setup a relation 1-n between two models

public boolean existsBelongsTo (string $modelName, string $modelRelation)

Checks whether a model has a belongsTo relation with another model

public boolean existsHasMany (string $modelName, string $modelRelation)

Checks whether a model has a hasMany relation with another model

public boolean existsHasOne (string $modelName, string $modelRelation)

Checks whether a model has a hasOne relation with another model

protected Phalcon\Mvc\Model\Resultset\Simple _getRelationRecords ()

Helper method to query records based on a relation definition

public Phalcon\Mvc\Model\ResultsetInterface getBelongsToRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, array $parameters)

Gets belongsTo related records from a model

public Phalcon\Mvc\Model\ResultsetInterface getHasManyRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, array $parameters)

Gets hasMany related records from a model

public Phalcon\Mvc\Model\ResultsetInterface getHasOneRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, array $parameters)

Gets belongsTo related records from a model

public array getBelongsTo (Phalcon\Mvc\ModelInterface $model)

Gets belongsTo relations defined on a model

public array getHasMany (Phalcon\Mvc\ModelInterface $model)

Gets hasMany relations defined on a model

public array getHasOne (Phalcon\Mvc\ModelInterface $model)

Gets hasOne relations defined on a model

public array getHasOneAndHasMany (Phalcon\Mvc\ModelInterface $model)

Gets hasOne relations defined on a model

public array getRelations (string $first, string $second)

Query the relationships between two models

public Phalcon\Mvc\Model\Query createQuery (string $phql)

Creates a Phalcon\Mvc\Model\Query without execute it

public Phalcon\Mvc\Model\Query executeQuery (string $phql, array $placeholders)

Creates a Phalcon\Mvc\Model\Query and execute it

public Phalcon\Mvc\Model\Query\Builder createBuilder (string $params)

Creates a Phalcon\Mvc\Model\Query\Builder