PHP Класс RedBeanPHP\AssociationManager

Manages simple bean associations.
Автор: Gabor de Mooij and the RedBeanPHP Community
Наследование: extends redbeanphp\Observable
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$adapter RedBeanPHP\Adapter\DBAdapter
$oodb redbeanphp\OODB
$writer RedBeanPHP\QueryWriter

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

Метод Описание
__construct ( ToolBox $tools ) Constructor
associate ( redbeanphp\OODBBean | array $beans1, redbeanphp\OODBBean | array $beans2 ) : array Associates two beans in a many-to-many relation.
clearRelations ( redbeanphp\OODBBean $bean, string $type ) : void Removes all relations for a bean. This method breaks every connection between a certain bean $bean and every other bean of type $type. Warning: this method is really fast because it uses a direct SQL query however it does not inform the models about this. If you want to notify FUSE models about deletion use a foreach-loop with unassociate() instead. (that might be slower though)
getTable ( array $types ) : string Creates a table name based on a types array.
related ( redbeanphp\OODBBean | array $bean, string $type, string $sql = '', array $bindings = [] ) : array Returns all the beans associated with $bean.
relatedCount ( redbeanphp\OODBBean | array $bean, string $type, string $sql = NULL, array $bindings = [] ) : integer Counts the number of related beans in an N-M relation.
unassociate ( $beans1, $beans2, boolean $fast = NULL ) : void Breaks the association between two beans. This method unassociates two beans. If the method succeeds the beans will no longer form an association. In the database this means that the association record will be removed. This method uses the OODB trash() method to remove the association links, thus giving FUSE models the opportunity to hook-in additional business logic. If the $fast parameter is set to boolean TRUE this method will remove the beans without their consent, bypassing FUSE. This can be used to improve performance.

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

Метод Описание
associateBeans ( redbeanphp\OODBBean $bean1, redbeanphp\OODBBean $bean2, redbeanphp\OODBBean $bean ) : mixed Associates a pair of beans. This method associates two beans, no matter what types. Accepts a base bean that contains data for the linking record.

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

Метод Описание
handleException ( Exception $exception ) : void Handles exceptions. Suppresses exceptions caused by missing structures.
relatedRows ( redbeanphp\OODBBean $bean, string $type, string $sql = '', array $bindings = [] ) : array Internal method.

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

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

Constructor
public __construct ( ToolBox $tools )
$tools ToolBox toolbox

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

This method will associate two beans and store the connection between the two in a link table. Instead of two single beans this method also accepts two sets of beans. Returns the ID or the IDs of the linking beans.
public associate ( redbeanphp\OODBBean | array $beans1, redbeanphp\OODBBean | array $beans2 ) : array
$beans1 redbeanphp\OODBBean | array one or more beans to form the association
$beans2 redbeanphp\OODBBean | array one or more beans to form the association
Результат array

associateBeans() защищенный Метод

This method is used by associate. This method also accepts a base bean to be used as the template for the link record in the database.
protected associateBeans ( redbeanphp\OODBBean $bean1, redbeanphp\OODBBean $bean2, redbeanphp\OODBBean $bean ) : mixed
$bean1 redbeanphp\OODBBean first bean
$bean2 redbeanphp\OODBBean second bean
$bean redbeanphp\OODBBean base bean (association record)
Результат mixed

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

Removes all relations for a bean. This method breaks every connection between a certain bean $bean and every other bean of type $type. Warning: this method is really fast because it uses a direct SQL query however it does not inform the models about this. If you want to notify FUSE models about deletion use a foreach-loop with unassociate() instead. (that might be slower though)
public clearRelations ( redbeanphp\OODBBean $bean, string $type ) : void
$bean redbeanphp\OODBBean reference bean
$type string type of beans that need to be unassociated
Результат void

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

Manages the get the correct name for the linking table for the types provided.
public getTable ( array $types ) : string
$types array 2 types as strings
Результат string

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

This method returns the number of beans of type $type associated with reference bean(s) $bean. The query can be tuned using an SQL snippet for additional filtering.
public relatedCount ( redbeanphp\OODBBean | array $bean, string $type, string $sql = NULL, array $bindings = [] ) : integer
$bean redbeanphp\OODBBean | array a bean object or an array of beans
$type string type of bean you're interested in
$sql string SQL snippet (optional)
$bindings array bindings for your SQL string
Результат integer

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

Breaks the association between two beans. This method unassociates two beans. If the method succeeds the beans will no longer form an association. In the database this means that the association record will be removed. This method uses the OODB trash() method to remove the association links, thus giving FUSE models the opportunity to hook-in additional business logic. If the $fast parameter is set to boolean TRUE this method will remove the beans without their consent, bypassing FUSE. This can be used to improve performance.
public unassociate ( $beans1, $beans2, boolean $fast = NULL ) : void
$fast boolean if TRUE, removes the entries by query without FUSE
Результат void

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

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

protected DBAdapter,RedBeanPHP\Adapter $adapter
Результат RedBeanPHP\Adapter\DBAdapter

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

protected OODB,redbeanphp $oodb
Результат redbeanphp\OODB

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

protected QueryWriter,RedBeanPHP $writer
Результат RedBeanPHP\QueryWriter