Doctrine 1.2.4
Doctrine_Relation Class Reference

Inherits ArrayAccess.

Inherited by Doctrine_Relation_Association, Doctrine_Relation_ForeignKey, and Doctrine_Relation_LocalKey.

Public Member Functions

 __construct (array $definition)
 
 __toString ()
 
 fetchRelatedFor (Doctrine_Record $record)
 
 getAlias ()
 
 getClass ()
 
 getForeign ()
 
 getForeignColumnName ()
 
 getForeignFieldName ()
 
 getForeignKeyName ()
 
 getLocal ()
 
 getLocalColumnName ()
 
 getLocalFieldName ()
 
 getOrderBy ($alias=null, $columnNames=false)
 
 getOrderByStatement ($alias=null, $columnNames=false)
 
 getRelationDql ($count)
 
 getTable ()
 
 getType ()
 
 hasConstraint ()
 
 isCascadeDelete ()
 
 isOneToOne ()
 
 toArray ()
 

Data Fields

const MANY = 1
 
const ONE = 0
 

Detailed Description

Definition at line 34 of file Relation.php.

Constructor & Destructor Documentation

array $definition see Doctrine_Relation::__construct ( array  $definition)

constructor

Parameters
array$definitionan 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

localTable the local table object

refTable the reference table object (if any)

onDelete referential delete action

onUpdate referential update action

deferred deferred constraint checking

alias relation alias

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

foreignKeyName the name of the dbms foreign key to create. Optional, if left blank Doctrine will generate one for you

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.

SET DEFAULT

Definition at line 128 of file Relation.php.

{
$def = array();
foreach ($this->definition as $key => $val) {
if ( ! isset($definition[$key]) && $val) {
throw new Doctrine_Exception($key . ' is required!');
}
if (isset($definition[$key])) {
$def[$key] = $definition[$key];
} else {
$def[$key] = $this->definition[$key];
}
}
$this->definition = $def;
}

Member Function Documentation

Doctrine_Relation::__toString ( )

__toString

Returns
string

Definition at line 444 of file Relation.php.

{
$r[] = "<pre>";
foreach ($this->definition as $k => $v) {
if (is_object($v)) {
$v = 'Object(' . get_class($v) . ')';
}
$r[] = $k . ' : ' . $v;
}
$r[] = "</pre>";
return implode("\n", $r);
}
Doctrine_Relation::fetchRelatedFor ( Doctrine_Record  $record)
abstract

fetchRelatedFor

fetches a component related to given record

Parameters
Doctrine_Record$record
Returns
Doctrine_Record|Doctrine_Collection
Doctrine_Relation::getAlias ( )
final

getAlias returns the relation alias

Returns
string

Definition at line 214 of file Relation.php.

{
return $this->definition['alias'];
}
Doctrine_Relation::getClass ( )
final

getClass returns the name of the related class

Returns
string

Definition at line 261 of file Relation.php.

{
return $this->definition['class'];
}
Doctrine_Relation::getForeign ( )
final

getForeign returns the name of the foreignkey column where the localkey column is pointing at

Returns
string

Definition at line 304 of file Relation.php.

{
return $this->definition['foreign'];
}
Doctrine_Relation::getForeignColumnName ( )
final

getForeignColumnName returns the column name of the foreign column

Returns
string $columnName

Definition at line 324 of file Relation.php.

{
return $this->definition['table']->getColumnName($this->definition['foreign']);
}
Doctrine_Relation::getForeignFieldName ( )
final

getLocalFieldName returns the field name of the foreign column

Definition at line 313 of file Relation.php.

{
return $this->definition['table']->getFieldName($this->definition['foreign']);
}
Doctrine_Relation::getForeignKeyName ( )

Get the name of the foreign key for this relationship

Returns
string $foreignKeyName

Definition at line 373 of file Relation.php.

{
if (isset($this->definition['foreignKeyName'])) {
return $this->definition['foreignKeyName'];
}
return $this['localTable']->getConnection()->generateUniqueRelationForeignKeyName($this);
}
Doctrine_Relation::getLocal ( )
final

getLocal returns the name of the local column

Returns
string

Definition at line 272 of file Relation.php.

{
return $this->definition['local'];
}
Doctrine_Relation::getLocalColumnName ( )
final

getLocalColumnName returns the column name of the local column

Returns
string $columnName

Definition at line 292 of file Relation.php.

{
return $this->definition['localTable']->getColumnName($this->definition['local']);
}
Doctrine_Relation::getLocalFieldName ( )
final

getLocalFieldName returns the field name of the local column

Definition at line 281 of file Relation.php.

{
return $this->definition['localTable']->getFieldName($this->definition['local']);
}
Doctrine_Relation::getOrderBy (   $alias = null,
  $columnNames = false 
)

Get the relationship orderby SQL/DQL

Parameters
string$aliasThe alias to use
boolean$columnNamesWhether or not to use column names instead of field names
Returns
string $orderBy

Definition at line 388 of file Relation.php.

{
if ( ! $alias) {
$alias = $this->getTable()->getComponentName();
}
if ($orderBy = $this->getOrderByStatement($alias, $columnNames)) {
return ' ORDER BY ' . $orderBy;
}
}
Doctrine_Relation::getOrderByStatement (   $alias = null,
  $columnNames = false 
)

Get the relationship orderby statement

Parameters
string$aliasThe alias to use
boolean$columnNamesWhether or not to use column names instead of field names
Returns
string $orderByStatement

Definition at line 406 of file Relation.php.

{
$table = $this->getTable();
if ( ! $alias) {
$alias = $table->getComponentName();
}
if (isset($this->definition['orderBy'])) {
return $table->processOrderBy($alias, $this->definition['orderBy'], $columnNames);
} else {
return $table->getOrderByStatement($alias, $columnNames);
}
}
Doctrine_Relation::getRelationDql (   $count)

getRelationDql

Parameters
integer$count
Returns
string

Definition at line 346 of file Relation.php.

{
$component = $this->getTable()->getComponentName();
$dql = 'FROM ' . $component
. ' WHERE ' . $component . '.' . $this->definition['foreign']
. ' IN (' . substr(str_repeat('?, ', $count), 0, -2) . ')'
. $this->getOrderBy($component);
return $dql;
}
Doctrine_Relation::getTable ( )
final

getTable returns the foreign table object

Returns
Doctrine_Table

Definition at line 248 of file Relation.php.

{
->getConnectionForComponent($this->definition['class'])
->getTable($this->definition['class']);
}
Doctrine_Relation::getType ( )
final

getType returns the relation type, either 0 or 1

See Also
Doctrine_Relation MANY_* and ONE_* constants
Returns
integer

Definition at line 226 of file Relation.php.

{
return $this->definition['type'];
}
Doctrine_Relation::hasConstraint ( )

hasConstraint whether or not this relation has an explicit constraint

Returns
boolean

Definition at line 150 of file Relation.php.

{
return ($this->definition['constraint'] ||
($this->definition['onUpdate']) ||
($this->definition['onDelete']));
}
Doctrine_Relation::isCascadeDelete ( )

Checks whether this relation cascades deletions to the related objects on the application level.

Returns
boolean

Definition at line 237 of file Relation.php.

{
return in_array('delete', $this->definition['cascade']);
}
Doctrine_Relation::isOneToOne ( )
final

isOneToOne returns whether or not this relation is a one-to-one relation

Returns
boolean

Definition at line 335 of file Relation.php.

{
return ($this->definition['type'] == Doctrine_Relation::ONE);
}
Doctrine_Relation::toArray ( )

toArray

Returns
array

Definition at line 203 of file Relation.php.

{
return $this->definition;
}

Field Documentation

const Doctrine_Relation::MANY = 1

constant for MANY_TO_MANY and ONE_TO_MANY relationships

Definition at line 48 of file Relation.php.

const Doctrine_Relation::ONE = 0

RELATION CONSTANTS constant for ONE_TO_ONE and MANY_TO_ONE relationships

Definition at line 43 of file Relation.php.


The documentation for this class was generated from the following file: