PHP Class RedBeanPHP\AssociationManager

Manages simple bean associations.
Author: Gabor de Mooij and the RedBeanPHP Community
Inheritance: extends redbeanphp\Observable
Afficher le fichier Open project: gabordemooij/redbean Class Usage Examples

Protected Properties

Свойство Type Description
$adapter RedBeanPHP\Adapter\DBAdapter
$oodb redbeanphp\OODB
$writer RedBeanPHP\QueryWriter

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
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.

Method Details

__construct() public méthode

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

associate() public méthode

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
Résultat array

associateBeans() protected méthode

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)
Résultat mixed

clearRelations() public méthode

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
Résultat void

getTable() public méthode

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
Résultat string

relatedCount() public méthode

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
Résultat integer

unassociate() public méthode

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
Résultat void

Property Details

$adapter protected_oe property

protected DBAdapter,RedBeanPHP\Adapter $adapter
Résultat RedBeanPHP\Adapter\DBAdapter

$oodb protected_oe property

protected OODB,redbeanphp $oodb
Résultat redbeanphp\OODB

$writer protected_oe property

protected QueryWriter,RedBeanPHP $writer
Résultat RedBeanPHP\QueryWriter