PHP Класс FOF30\Model\DataModel\RelationManager

Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$eager A list of the names of eager loaded relations
$parentModel The data model we are attached to
$relationTypes The known relation types
$relations The relations known to us

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

Метод Описание
__call ( string $name, array $arguments ) : DataModel A magic method which allows us to define relations using shorthand notation, e.g. $manager->hasOne('phone') instead of $manager->addRelation('phone', 'hasOne')
__clone ( ) Implements deep cloning of the relation object
__construct ( DataModel $parentModel ) Creates a new relation manager for the defined parent model
__get ( $name ) : Collection Magic method to get the data of a relation using shorthand notation, e.g. $manager->phone instead of $manager->getData('phone')
addRelation ( string $name, string $type, string $foreignModelName = null, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null ) : DataModel Adds a relation to the relation manager
getCountSubquery ( string $name, string $tableAlias = null ) : JDatabaseQuery Returns the count sub-query for a relation, used for relation filters (whereHas in the DataModel).
getData ( string $name, callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel Gets the related items of a relation
getForeignKeyMap ( string $name ) : array Gets the foreign key map of a many-to-many relation
getNew ( string $name ) : DataModel Get a new related item which satisfies relation $name and adds it to this relation's data list.
getRelation ( string $name ) : Relation Gets the related items of a relation
getRelationNames ( ) : array Returns a list of all known relations' names
getRelationTypes ( ) : array Populates the static map of relation type methods and relation handling classes
isMagicMethod ( string $name ) : boolean Is $name a magic-callable method?
isMagicProperty ( string $name ) : boolean Is $name a magic property? Corollary: returns true if a relation of this name is known to the relation manager.
rebase ( DataModel $parentModel ) Rebase a relation manager
removeRelation ( string $name ) : DataModel Removes a known relation
resetRelationData ( array $relationsToReset = [] ) Resets the data of all relations in this manager. This doesn't remove relations, just their data so that they get loaded again.
resetRelations ( ) Removes all known relations
save ( null | string $name = null ) : DataModel Saves all related items belonging to the specified relation or, if $name is null, all known relations which support saving.
setDataFromCollection ( string $name, Collection &$data, mixed $keyMap = null ) : void Populates the internal $this->data collection of a relation from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.

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

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

You can also use it to get data of a relation using shorthand notation, e.g. $manager->getPhone($callback) instead of $manager->getData('phone', $callback);
public __call ( string $name, array $arguments ) : DataModel
$name string The magic method to call
$arguments array The arguments to the magic method
Результат FOF30\Model\DataModel The parent model, for chaining

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

Implements deep cloning of the relation object
public __clone ( )

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

Creates a new relation manager for the defined parent model
public __construct ( DataModel $parentModel )
$parentModel FOF30\Model\DataModel The model we are attached to

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

Magic method to get the data of a relation using shorthand notation, e.g. $manager->phone instead of $manager->getData('phone')
public __get ( $name ) : Collection
$name
Результат Collection

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

Adds a relation to the relation manager
public addRelation ( string $name, string $type, string $foreignModelName = null, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null ) : DataModel
$name string The name of the relation as known to this relation manager, e.g. 'phone'
$type string The relation type, e.g. 'hasOne'
$foreignModelName string The name of the foreign key's model in the format "modelName@com_something"
$localKey string The local table key for this relation
$foreignKey string The foreign key for this relation
$pivotTable string For many-to-many relations, the pivot (glue) table
$pivotLocalKey string For many-to-many relations, the pivot table's column storing the local key
$pivotForeignKey string For many-to-many relations, the pivot table's column storing the foreign key
Результат FOF30\Model\DataModel The parent model, for chaining

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

Returns the count sub-query for a relation, used for relation filters (whereHas in the DataModel).
public getCountSubquery ( string $name, string $tableAlias = null ) : JDatabaseQuery
$name string The relation to get the sub-query for
$tableAlias string The alias to use for the local table
Результат JDatabaseQuery

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

Gets the related items of a relation
См. также: Relation::getData()
public getData ( string $name, callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel
$name string The name of the relation to return data for
$callback callable A callback to customise the returned data
$dataCollection FOF30\Utils\Collection Used when fetching the data of an eager loaded relation
Результат Collection | DataModel

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

Gets the foreign key map of a many-to-many relation
public getForeignKeyMap ( string $name ) : array
$name string The name of the relation to return data for
Результат array

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

Get a new related item which satisfies relation $name and adds it to this relation's data list.
public getNew ( string $name ) : DataModel
$name string The relation based on which a new item is returned
Результат FOF30\Model\DataModel

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

Gets the related items of a relation
public getRelation ( string $name ) : Relation
$name string The name of the relation to return data for
Результат Relation

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

Returns a list of all known relations' names
public getRelationNames ( ) : array
Результат array

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

Populates the static map of relation type methods and relation handling classes
public static getRelationTypes ( ) : array
Результат array Key = method name, Value = relation handling class

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

Is $name a magic-callable method?
public isMagicMethod ( string $name ) : boolean
$name string The name of a potential magic-callable method
Результат boolean

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

Is $name a magic property? Corollary: returns true if a relation of this name is known to the relation manager.
public isMagicProperty ( string $name ) : boolean
$name string The name of a potential magic property
Результат boolean

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

Rebase a relation manager
public rebase ( DataModel $parentModel )
$parentModel FOF30\Model\DataModel

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

Removes a known relation
public removeRelation ( string $name ) : DataModel
$name string The name of the relation to remove
Результат FOF30\Model\DataModel The parent model, for chaining

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

Resets the data of all relations in this manager. This doesn't remove relations, just their data so that they get loaded again.
public resetRelationData ( array $relationsToReset = [] )
$relationsToReset array The names of the relations to reset. Pass an empty array (default) to reset all relations.

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

Removes all known relations
public resetRelations ( )

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

Saves all related items belonging to the specified relation or, if $name is null, all known relations which support saving.
public save ( null | string $name = null ) : DataModel
$name null | string The relation to save, or null to save all known relations
Результат FOF30\Model\DataModel The parent model, for chaining

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

Populates the internal $this->data collection of a relation from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.
public setDataFromCollection ( string $name, Collection &$data, mixed $keyMap = null ) : void
$name string Relation name
$data Collection The relation data to push into this relation
$keyMap mixed Used by many-to-many relations to pass around the local to foreign key map
Результат void

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

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

A list of the names of eager loaded relations
protected $eager

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

The data model we are attached to
protected $parentModel

$relationTypes защищенное статическое свойство

The known relation types
protected static $relationTypes

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

The relations known to us
protected $relations