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

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

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

Свойство Тип Описание
$container The component container for this relation
$data The data loaded by this relation
$foreignKey The foreign table key for this relation
$foreignKeyMap Maps each local table key to an array of foreign table keys, used in many-to-many relations
$foreignModelClass The class name of the foreign key's model
$foreignModelComponent The application name of the foreign model
$foreignModelName The bade name of the foreign model
$localKey The local table key for this relation
$parentModel The data model we are attached to
$pivotForeignKey For many-to-many relations, the pivot table's column storing the foreign key
$pivotLocalKey For many-to-many relations, the pivot table's column storing the local key
$pivotTable For many-to-many relations, the pivot (glue) table

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

Метод Описание
__construct ( DataModel $parentModel, string $foreignModelName, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null ) Public constructor. Initialises the relation.
getCountSubquery ( ) : JDatabaseQuery Returns the count subquery for DataModel's has() and whereHas() methods.
getData ( callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel Get the relation data.
getForeignKeyMap ( ) : array Returns the foreign key map of a many-to-many relation, used for eager loading many-to-many relations
getForeignModel ( array $config = [] ) : DataModel Gets an object instance of the foreign model
getLocalKey ( ) : string Returns the name of the local key of the relation
getNew ( ) : DataModel Returns a new item of the foreignModel type, pre-initialised to fulfil this relation
rebase ( DataModel $model ) Rebase the relation to a different model
reset ( ) Reset the relation data
saveAll ( ) Saves all related items. You can use it to touch items as well: every item being saved causes the modified_by and modified_on fields to be changed automatically, thanks to the DataModel's magic.
setDataFromCollection ( Collection &$data, mixed $keyMap = null ) : void Populates the internal $this->data collection from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.

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

Метод Описание
filterForeignModel ( DataModel $foreignModel, Collection $dataCollection = null ) : boolean Applies the relation filters to the foreign model when getData is called

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

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

Public constructor. Initialises the relation.
public __construct ( DataModel $parentModel, string $foreignModelName, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null )
$parentModel FOF30\Model\DataModel The data model we are attached to
$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

filterForeignModel() абстрактный защищенный Метод

Applies the relation filters to the foreign model when getData is called
abstract protected filterForeignModel ( DataModel $foreignModel, Collection $dataCollection = null ) : boolean
$foreignModel FOF30\Model\DataModel The foreign model you're operating on
$dataCollection Collection If it's an eager loaded relation, the collection of loaded parent records
Результат boolean Return false to force an empty data collection

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

Returns the count subquery for DataModel's has() and whereHas() methods.
abstract public getCountSubquery ( ) : JDatabaseQuery
Результат JDatabaseQuery

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

If you want to apply additional filtering to the foreign model, use the $callback. It can be any function, static method, public method or closure with an interface of function(DataModel $foreignModel). You are not supposed to return anything, just modify $foreignModel's state directly. For example, you may want to do: $foreignModel->setState('foo', 'bar')
public getData ( callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel
$callback callable The callback to run on the remote model.
$dataCollection Collection
Результат Collection | DataModel

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

Returns the foreign key map of a many-to-many relation, used for eager loading many-to-many relations
public getForeignKeyMap ( ) : array
Результат array

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

Gets an object instance of the foreign model
public getForeignModel ( array $config = [] ) : DataModel
$config array Optional configuration information for the Model
Результат FOF30\Model\DataModel

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

Returns the name of the local key of the relation
public getLocalKey ( ) : string
Результат string

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

Returns a new item of the foreignModel type, pre-initialised to fulfil this relation
abstract public getNew ( ) : DataModel
Результат FOF30\Model\DataModel

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

Rebase the relation to a different model
public rebase ( DataModel $model )
$model FOF30\Model\DataModel

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

Reset the relation data
public reset ( )

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

Saves all related items. You can use it to touch items as well: every item being saved causes the modified_by and modified_on fields to be changed automatically, thanks to the DataModel's magic.
public saveAll ( )

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

Populates the internal $this->data collection 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 ( Collection &$data, mixed $keyMap = null ) : void
$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

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

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

The component container for this relation
protected $container

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

The data loaded by this relation
protected $data

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

The foreign table key for this relation
protected $foreignKey

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

Maps each local table key to an array of foreign table keys, used in many-to-many relations
protected $foreignKeyMap

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

The class name of the foreign key's model
protected $foreignModelClass

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

The application name of the foreign model
protected $foreignModelComponent

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

The bade name of the foreign model
protected $foreignModelName

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

The local table key for this relation
protected $localKey

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

The data model we are attached to
protected $parentModel

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

For many-to-many relations, the pivot table's column storing the foreign key
protected $pivotForeignKey

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

For many-to-many relations, the pivot table's column storing the local key
protected $pivotLocalKey

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

For many-to-many relations, the pivot (glue) table
protected $pivotTable