Overview

Namespaces

  • None
  • RedBeanPHP
    • Adapter
    • BeanHelper
    • Cursor
    • Driver
    • Logger
      • RDefault
    • QueryWriter
    • RedException
    • Repository
    • Util

Classes

  • AssociationManager
  • BeanCollection
  • DuplicationManager
  • Facade
  • Finder
  • Jsonable
  • LabelMaker
  • Observable
  • OODB
  • OODBBean
  • R
  • Repository
  • SimpleModel
  • SimpleModelHelper
  • TagManager
  • ToolBox

Interfaces

  • Adapter
  • BeanHelper
  • Cursor
  • Driver
  • Logger
  • Observer
  • Plugin
  • QueryWriter

Exceptions

  • RedException
  • Overview
  • Namespace
  • Class

Class AssociationManager

Association Manager. Manages simple bean associations.

RedBeanPHP\Observable
Extended by RedBeanPHP\AssociationManager
Namespace: RedBeanPHP
Copyright:

(c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community. This source file is subject to the BSD/GPLv2 License that is bundled with this source code in the file license.txt.


License: BSD/GPLv2
Author: Gabor de Mooij and the RedBeanPHP Community
File: RedBeanPHP/AssociationManager.php
Located at AssociationManager.php
Methods summary
protected mixed
# associateBeans( RedBeanPHP\OODBBean $bean1, RedBeanPHP\OODBBean $bean2, RedBeanPHP\OODBBean $bean )

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. 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.

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. 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.

Parameters

$bean1
first bean
$bean2
second bean
$bean
base bean (association record)

Returns

mixed
public
# __construct( RedBeanPHP\ToolBox $tools )

Constructor

Constructor

Parameters

$tools
toolbox
public string
# getTable( array $types )

Creates a table name based on a types array. Manages the get the correct name for the linking table for the types provided.

Creates a table name based on a types array. Manages the get the correct name for the linking table for the types provided.

Parameters

$types
2 types as strings

Returns

string
public array
# associate( RedBeanPHP\OODBBean|array $beans1, RedBeanPHP\OODBBean|array $beans2 )

Associates two beans in a many-to-many relation. 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.

Associates two beans in a many-to-many relation. 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.

Parameters

$beans1
one or more beans to form the association
$beans2
one or more beans to form the association

Returns

array
public integer
# relatedCount( RedBeanPHP\OODBBean|array $bean, string $type, string $sql = NULL, array $bindings = array() )

Counts the number of related beans in an N-M relation. 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.

Counts the number of related beans in an N-M relation. 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.

Parameters

$bean
a bean object or an array of beans
$type
type of bean you're interested in
$sql
SQL snippet (optional)
$bindings
bindings for your SQL string

Returns

integer
public
# unassociate( RedBeanPHP\OODBBean $beans1, RedBeanPHP\OODBBean $beans2, boolean $fast = NULL )

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.

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.

Parameters

$beans1
$bean1 first bean in target association
$beans2
$bean2 second bean in target association
$fast
if TRUE, removes the entries by query without FUSE
public
# clearRelations( RedBeanPHP\OODBBean $bean, string $type )

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)

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)

Parameters

$bean
reference bean
$type
type of beans that need to be unassociated
public array
# related( RedBeanPHP\OODBBean|array $bean, string $type, string $sql = '', array $bindings = array() )

Returns all the beans associated with $bean. This method will return an array containing all the beans that have been associated once with the associate() function and are still associated with the bean specified. The type parameter indicates the type of beans you are looking for. You can also pass some extra SQL and values for that SQL to filter your results after fetching the related beans.

Returns all the beans associated with $bean. This method will return an array containing all the beans that have been associated once with the associate() function and are still associated with the bean specified. The type parameter indicates the type of beans you are looking for. You can also pass some extra SQL and values for that SQL to filter your results after fetching the related beans.

Don't try to make use of subqueries, a subquery using IN() seems to be slower than two queries!

Since 3.2, you can now also pass an array of beans instead just one bean as the first parameter.

Parameters

$bean
the bean you have
$type
the type of beans you want
$sql
SQL snippet for extra filtering
$bindings
values to be inserted in SQL slots

Returns

array
Methods inherited from RedBeanPHP\Observable
addEventListener(), signal()
Properties summary
protected RedBeanPHP\OODB $oodb
#
protected RedBeanPHP\Adapter\DBAdapter $adapter
#
protected RedBeanPHP\QueryWriter $writer
#
API documentation generated by ApiGen