Doctrine 1.2.4
Doctrine_Relation_ForeignKey Class Reference

Inherits Doctrine_Relation.

Public Member Functions

 __toString ()
 
 fetchRelatedFor (Doctrine_Record $record)
 
 getAlias ()
 
 getClass ()
 
 getCondition ($alias=null)
 
 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 ForeignKey.php.

Member Function Documentation

Doctrine_Relation::__toString ( )
inherited

__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_ForeignKey::fetchRelatedFor ( Doctrine_Record  $record)

fetchRelatedFor

fetches a component related to given record

Parameters
Doctrine_Record$record
Returns
Doctrine_Record|Doctrine_Collection

Definition at line 44 of file ForeignKey.php.

{
$id = array();
$localTable = $record->getTable();
foreach ((array) $this->definition['local'] as $local) {
$value = $record->get($localTable->getFieldName($local));
if (isset($value)) {
$id[] = $value;
}
}
if ($this->isOneToOne()) {
if ( ! $record->exists() || empty($id) ||
! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
. ' WHERE ' . $this->getCondition() . $this->getOrderBy(null, false);
$coll = $this->getTable()->getConnection()->query($dql, $id);
$related = $coll[0];
}
$related->set($related->getTable()->getFieldName($this->definition['foreign']),
$record, false);
} else {
if ( ! $record->exists() || empty($id) ||
! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
$related = Doctrine_Collection::create($this->getTable());
} else {
$query = $this->getRelationDql(1);
$related = $this->getTable()->getConnection()->query($query, $id);
}
$related->setReference($record, $this);
}
return $related;
}
Doctrine_Relation::getAlias ( )
finalinherited

getAlias returns the relation alias

Returns
string

Definition at line 214 of file Relation.php.

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

getClass returns the name of the related class

Returns
string

Definition at line 261 of file Relation.php.

{
return $this->definition['class'];
}
Doctrine_Relation_ForeignKey::getCondition (   $alias = null)

getCondition

Parameters
string$alias

Definition at line 89 of file ForeignKey.php.

{
if ( ! $alias) {
$alias = $this->getTable()->getComponentName();
}
$conditions = array();
foreach ((array) $this->definition['foreign'] as $foreign) {
$conditions[] = $alias . '.' . $foreign . ' = ?';
}
return implode(' AND ', $conditions);
}
Doctrine_Relation::getForeign ( )
finalinherited

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 ( )
finalinherited

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 ( )
finalinherited

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 ( )
inherited

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 ( )
finalinherited

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 ( )
finalinherited

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 ( )
finalinherited

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 
)
inherited

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 
)
inherited

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)
inherited

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 ( )
finalinherited

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 ( )
finalinherited

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 ( )
inherited

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 ( )
inherited

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 ( )
finalinherited

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 ( )
inherited

toArray

Returns
array

Definition at line 203 of file Relation.php.

{
return $this->definition;
}

Field Documentation

const Doctrine_Relation::MANY = 1
inherited

constant for MANY_TO_MANY and ONE_TO_MANY relationships

Definition at line 48 of file Relation.php.

const Doctrine_Relation::ONE = 0
inherited

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: