PHP 클래스 RedBeanPHP\AssociationManager

Manages simple bean associations.
저자: Gabor de Mooij and the RedBeanPHP Community
상속: extends redbeanphp\Observable
파일 보기 프로젝트 열기: gabordemooij/redbean 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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