Source for file Relation.php
Documentation is available at Relation.php
* $Id: Relation.php 1973 2007-07-11 14:39:15Z zYne $
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* This class represents a relation between components
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @version $Revision: 1973 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* constant for ONE_TO_ONE and MANY_TO_ONE aggregate relationships
* constant for ONE_TO_ONE and MANY_TO_ONE composite relationships
* constant for MANY_TO_MANY and ONE_TO_MANY aggregate relationships
const MANY_AGGREGATE =
2;
* constant for MANY_TO_MANY and ONE_TO_MANY composite relationships
const MANY_COMPOSITE =
3;
* @param array $definition an associative array with the following structure:
* name foreign key constraint name
* local the local field(s)
* foreign the foreign reference field(s)
* table the foreign table object
* refTable the reference table object (if any)
* onDelete referential delete action
* onUpdate referential update action
* deferred deferred constraint checking
* type the relation type, either Doctrine_Relation::ONE or Doctrine_Relation::MANY
* constraint boolean value, true if the relation has an explicit referential integrity constraint
* The onDelete and onUpdate keys accept the following values:
* CASCADE: Delete or update the row from the parent table and automatically delete or
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
* in the parent table or in the child table.
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
* key value is not allowed to proceed if there is a related foreign key value in the referenced table.
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
* omitting the ON DELETE or ON UPDATE clause.
foreach ($this->definition as $key =>
$val) {
if ( ! isset
($definition[$key]) &&
$val) {
if (isset
($definition[$key])) {
$def[$key] =
$definition[$key];
$this->definition =
$def;
* whether or not this relation has an explicit constraint
* returns the relation alias
* returns the relation type, either 0 or 1
* @see Doctrine_Relation MANY_* and ONE_* constants
* returns the foreign table object
* @return object Doctrine_Table
->getConnectionForComponent($this->definition['class'])
* returns the name of the local column
* returns the name of the foreignkey column where
* the localkey column is pointing at
* returns whether or not this relation is a composite relation
* returns whether or not this relation is a one-to-one relation
$component =
$this->getTable()->getComponentName();
$dql =
'FROM ' .
$component
.
' WHERE ' .
$component .
'.' .
$this->definition['foreign']
* fetches a component related to given record
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection