diff --git a/lib/Doctrine/Association.php b/lib/Doctrine/Association.php index b38306f1b..b3daa21dd 100644 --- a/lib/Doctrine/Association.php +++ b/lib/Doctrine/Association.php @@ -19,7 +19,7 @@ * . */ /** - * Doctrine_Association this class takes care of association mapping + * Doctrine_Relation_Association this class takes care of association mapping * (= many-to-many relationships, where the relationship is handled with an additional relational table * which holds 2 foreign keys) * @@ -28,7 +28,7 @@ * @url www.phpdoctrine.com * @license LGPL */ -class Doctrine_Association extends Doctrine_Relation { +class Doctrine_Relation_Association extends Doctrine_Relation { /** * @var Doctrine_Table $associationTable */ diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 058d262d8..3e3e22ac0 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -243,8 +243,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $this->reference = $record; $this->relation = $relation; - if($relation instanceof Doctrine_ForeignKey || - $relation instanceof Doctrine_LocalKey) { + if($relation instanceof Doctrine_Relation_ForeignKey || + $relation instanceof Doctrine_Relation_LocalKey) { $this->reference_field = $relation->getForeign(); @@ -257,7 +257,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $record->set($this->reference_field, $this->reference, false); } } - } elseif($relation instanceof Doctrine_Association) { + } elseif($relation instanceof Doctrine_Relation_Association) { } } @@ -315,7 +315,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator endswitch; if(isset($this->relation)) { - if($this->relation instanceof Doctrine_ForeignKey) { + if($this->relation instanceof Doctrine_Relation_ForeignKey) { $params[] = $this->reference->getIncremented(); $where[] = $this->reference_field." = ?"; @@ -331,7 +331,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } - } elseif($this->relation instanceof Doctrine_Association) { + } elseif($this->relation instanceof Doctrine_Relation_Association) { $asf = $this->relation->getAssociationFactory(); $query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); @@ -582,7 +582,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $local = $rel->getLocal(); $list = array(); - if($rel instanceof Doctrine_LocalKey || $rel instanceof Doctrine_ForeignKey) { + if($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) { foreach($this->data as $record): $list[] = $record[$local]; endforeach; @@ -613,7 +613,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $foreign = $rel->getForeign(); $local = $rel->getLocal(); - if($rel instanceof Doctrine_LocalKey) { + if($rel instanceof Doctrine_Relation_LocalKey) { foreach($this->data as $key => $record) { foreach($coll as $k => $related) { if($related[$foreign] == $record[$local]) { @@ -621,7 +621,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } } } - } elseif($rel instanceof Doctrine_ForeignKey) { + } elseif($rel instanceof Doctrine_Relation_ForeignKey) { foreach($this->data as $key => $record) { if($record->getState() == Doctrine_Record::STATE_TCLEAN || $record->getState() == Doctrine_Record::STATE_TDIRTY) @@ -638,7 +638,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $this->data[$key]->setRelated($name, $sub); } - } elseif($rel instanceof Doctrine_Association) { + } elseif($rel instanceof Doctrine_Relation_Association) { $identifier = $this->table->getIdentifier(); $asf = $rel->getAssociationFactory(); $name = $table->getComponentName(); diff --git a/lib/Doctrine/Compiler.php b/lib/Doctrine/Compiler.php index 014db4ee0..16ccfc988 100644 --- a/lib/Doctrine/Compiler.php +++ b/lib/Doctrine/Compiler.php @@ -20,8 +20,8 @@ */ /** - * Doctrine - * the base class of Doctrine framework + * Doctrine_Compiler + * This class can be used for compiling the entire Doctrine framework into a single file * * @package Doctrine * @author Konsta Vesterinen @@ -104,7 +104,7 @@ class Doctrine_Compiler { echo "Adding $file" . PHP_EOL; if( ! file_exists($file)) - throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists."); + throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists."); Doctrine::autoload($class); $refl = new ReflectionClass ( $class ); @@ -129,11 +129,10 @@ class Doctrine_Compiler { $fp = @fopen($target, 'w'); if ($fp === false) - throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $target"); + throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target"); fwrite($fp, ". + */ + +/** + * Doctrine_Compiler_Exception + * + * @package Doctrine + * @author Konsta Vesterinen + * @license LGPL + */ +class Doctrine_Compiler_Exception extends Doctrine_Exception { } diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index e684eea36..78d8320d2 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -459,8 +459,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $saveLater = array(); foreach($record->getReferences() as $k=>$v) { $fk = $record->getTable()->getRelation($k); - if($fk instanceof Doctrine_ForeignKey || - $fk instanceof Doctrine_LocalKey) { + if($fk instanceof Doctrine_Relation_ForeignKey || + $fk instanceof Doctrine_Relation_LocalKey) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: @@ -482,7 +482,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } break; endswitch; - } elseif($fk instanceof Doctrine_Association) { + } elseif($fk instanceof Doctrine_Relation_Association) { $v->save(); } } @@ -517,7 +517,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $name = $table->getComponentName(); $alias = $this->table->getAlias($name); - if($rel instanceof Doctrine_Association) { + if($rel instanceof Doctrine_Relation_Association) { switch($rel->getType()): case Doctrine_Relation::MANY_COMPOSITE: break; @@ -552,8 +552,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } break; endswitch; - } elseif($fk instanceof Doctrine_ForeignKey || - $fk instanceof Doctrine_LocalKey) { + } elseif($fk instanceof Doctrine_Relation_ForeignKey || + $fk instanceof Doctrine_Relation_LocalKey) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 85ce43e7e..92941c66b 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -68,7 +68,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable { // group relations foreach($rels as $key => $rel) { - if($rel instanceof Doctrine_ForeignKey) { + if($rel instanceof Doctrine_Relation_ForeignKey) { unset($rels[$key]); array_unshift($rels, $rel); } @@ -83,7 +83,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable { if($name === $nm) continue; - if($rel instanceof Doctrine_ForeignKey) { + if($rel instanceof Doctrine_Relation_ForeignKey) { if($index2 !== false) { if($index2 >= $index) continue; @@ -95,7 +95,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable { $tree[] = $name; } - } elseif($rel instanceof Doctrine_LocalKey) { + } elseif($rel instanceof Doctrine_Relation_LocalKey) { if($index2 !== false) { if($index2 <= $index) continue; @@ -106,7 +106,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable { array_unshift($tree,$name); $index++; } - } elseif($rel instanceof Doctrine_Association) { + } elseif($rel instanceof Doctrine_Relation_Association) { $t = $rel->getAssociationFactory(); $n = $t->getComponentName(); diff --git a/lib/Doctrine/ForeignKey.php b/lib/Doctrine/ForeignKey.php index f989225b3..1de724a61 100644 --- a/lib/Doctrine/ForeignKey.php +++ b/lib/Doctrine/ForeignKey.php @@ -20,14 +20,14 @@ */ Doctrine::autoload('Doctrine_Relation'); /** - * Doctrine_ForeignKey + * Doctrine_Relation_ForeignKey * This class represents a foreign key relation * * @author Konsta Vesterinen * @license LGPL * @package Doctrine */ -class Doctrine_ForeignKey extends Doctrine_Relation { +class Doctrine_Relation_ForeignKey extends Doctrine_Relation { /** * fetchRelatedFor * @@ -35,7 +35,7 @@ class Doctrine_ForeignKey extends Doctrine_Relation { * * @param Doctrine_Record $record * @return Doctrine_Record|Doctrine_Collection - */ + */ public function fetchRelatedFor(Doctrine_Record $record) { $id = $record->get($this->local); diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index a10228ecc..385eea636 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -391,7 +391,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { if($fk->isOneToOne()) { // one-to-one relation - if($fk instanceof Doctrine_LocalKey) + if($fk instanceof Doctrine_Relation_LocalKey) $last->set($fk->getLocal(), $record->getIncremented(), false); $last->set($fk->getAlias(), $record); diff --git a/lib/Doctrine/LocalKey.php b/lib/Doctrine/LocalKey.php index f4a2aac17..f3403709e 100644 --- a/lib/Doctrine/LocalKey.php +++ b/lib/Doctrine/LocalKey.php @@ -20,14 +20,14 @@ */ Doctrine::autoload('Doctrine_Relation'); /** - * Doctrine_LocalKey + * Doctrine_Relation_LocalKey * This class represents a local key relation * * @author Konsta Vesterinen * @license LGPL * @package Doctrine */ -class Doctrine_LocalKey extends Doctrine_Relation { +class Doctrine_Relation_LocalKey extends Doctrine_Relation { /** * fetchRelatedFor * diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 8ec97d35b..7d54a3939 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -115,13 +115,22 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera * * @return Doctrine_Manager */ - final public static function getInstance() { + public static function getInstance() { static $instance; if( ! isset($instance)) $instance = new self(); return $instance; } + /** + * connection + * a short cut for Doctrine_Manager::getInstance()->openConnection($dbh); + * + * @return Doctrine_Connection + */ + public static function connection(PDO $dbh) { + return Doctrine_Manager::getInstance()->openConnection($dbh); + } /** * install * diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 25198ea23..3151380ba 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -732,12 +732,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $this->needsSubquery = true; } - if($fk instanceof Doctrine_ForeignKey || - $fk instanceof Doctrine_LocalKey) { + if($fk instanceof Doctrine_Relation_ForeignKey || + $fk instanceof Doctrine_Relation_LocalKey) { $this->parts["join"][$tname][$tname2] = $join.$aliasString." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign(); - } elseif($fk instanceof Doctrine_Association) { + } elseif($fk instanceof Doctrine_Relation_Association) { $asf = $fk->getAssociationFactory(); $assocTableName = $asf->getTableName(); diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index f89e4f542..578b2f237 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -742,8 +742,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $rel = $this->table->getRelation($name); // one-to-many or one-to-one relation - if($rel instanceof Doctrine_ForeignKey || - $rel instanceof Doctrine_LocalKey) { + if($rel instanceof Doctrine_Relation_ForeignKey || + $rel instanceof Doctrine_Relation_LocalKey) { switch($rel->getType()) { case Doctrine_Relation::MANY_COMPOSITE: case Doctrine_Relation::MANY_AGGREGATE: @@ -767,7 +767,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite break; } - } elseif($rel instanceof Doctrine_Association) { + } elseif($rel instanceof Doctrine_Relation_Association) { // join table relation found if( ! ($value instanceof Doctrine_Collection)) throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references."); @@ -979,11 +979,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $name = $table->getComponentName(); $alias = $this->table->getAlias($name); - if($fk instanceof Doctrine_Association) { + if($fk instanceof Doctrine_Relation_Association) { switch($fk->getType()): - case Doctrine_Relation::MANY_COMPOSITE: - - break; case Doctrine_Relation::MANY_AGGREGATE: $asf = $fk->getAssociationFactory(); @@ -1015,8 +1012,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite } break; endswitch; - } elseif($fk instanceof Doctrine_ForeignKey || - $fk instanceof Doctrine_LocalKey) { + } elseif($fk instanceof Doctrine_Relation_ForeignKey || + $fk instanceof Doctrine_Relation_LocalKey) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: @@ -1168,7 +1165,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite return false; if( ! $connector->isOneToOne()) { - if( ! ($connector instanceof Doctrine_Association)) + if( ! ($connector instanceof Doctrine_Relation_Association)) $coll->setReference($this, $connector); $this->references[$alias] = $coll; @@ -1216,7 +1213,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return void */ final public function loadReference($name) { - $fk = $this->table->getRelation($name); if($fk->isOneToOne()) { diff --git a/lib/Doctrine/Relation/Association.php b/lib/Doctrine/Relation/Association.php new file mode 100644 index 000000000..b3daa21dd --- /dev/null +++ b/lib/Doctrine/Relation/Association.php @@ -0,0 +1,99 @@ +. + */ +/** + * Doctrine_Relation_Association this class takes care of association mapping + * (= many-to-many relationships, where the relationship is handled with an additional relational table + * which holds 2 foreign keys) + * + * + * @package Doctrine ORM + * @url www.phpdoctrine.com + * @license LGPL + */ +class Doctrine_Relation_Association extends Doctrine_Relation { + /** + * @var Doctrine_Table $associationTable + */ + protected $associationTable; + /** + * the constructor + * @param Doctrine_Table $table foreign factory object + * @param Doctrine_Table $associationTable factory which handles the association + * @param string $local local field name + * @param string $foreign foreign field name + * @param integer $type type of relation + * @see Doctrine_Table constants + */ + public function __construct(Doctrine_Table $table, Doctrine_Table $associationTable, $local, $foreign, $type, $alias) { + parent::__construct($table, $local, $foreign, $type, $alias); + $this->associationTable = $associationTable; + } + /** + * @return Doctrine_Table + */ + public function getAssociationFactory() { + return $this->associationTable; + } + /** + * getRelationDql + * + * @param integer $count + * @return string + */ + public function getRelationDql($count, $context = 'record') { + switch($context): + case "record": + $sub = "SELECT ".$this->foreign. + " FROM ".$this->associationTable->getTableName(). + " WHERE ".$this->local. + " IN (".substr(str_repeat("?, ", $count),0,-2).")"; + + $dql = "FROM ".$this->table->getComponentName(); + $dql .= ".".$this->associationTable->getComponentName(); + $dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)"; + break; + case "collection": + $sub = substr(str_repeat("?, ", $count),0,-2); + $dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName(); + $dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)"; + endswitch; + + return $dql; + } + /** + * fetchRelatedFor + * + * fetches a component related to given record + * + * @param Doctrine_Record $record + * @return Doctrine_Record|Doctrine_Collection + */ + public function fetchRelatedFor(Doctrine_Record $record) { + $id = $record->getIncremented(); + if(empty($id)) + $coll = new Doctrine_Collection($this->table); + else + $coll = Doctrine_Query::create()->parseQuery($this->getRelationDql(1))->execute(array($id)); + + return $coll; + } +} + diff --git a/lib/Doctrine/Relation/Association/Self.php b/lib/Doctrine/Relation/Association/Self.php new file mode 100644 index 000000000..5177b0bc7 --- /dev/null +++ b/lib/Doctrine/Relation/Association/Self.php @@ -0,0 +1,90 @@ +. + */ + +class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association { + /** + * getRelationDql + * + * @param integer $count + * @return string + */ + public function getRelationDql($count, $context = 'record') { + switch($context): + case "record": + $sub = "SELECT ".$this->foreign. + " FROM ".$this->associationTable->getTableName(). + " WHERE ".$this->local. + " = ?"; + $sub2 = "SELECT ".$this->local. + " FROM ".$this->associationTable->getTableName(). + " WHERE ".$this->foreign. + " = ?"; + + + $dql = "FROM ".$this->table->getComponentName(); + $dql .= ".".$this->associationTable->getComponentName(); + $dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)"; + $dql .= " || ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub2)"; + break; + case "collection": + $sub = substr(str_repeat("?, ", $count),0,-2); + $dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName(); + $dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)"; + endswitch; + + return $dql; + } + + + public function fetchRelatedFor(Doctrine_Record $record) { + $id = $record->getIncremented(); + + $q = new Doctrine_RawSql(); + + $assocTable = $this->getAssociationFactory()->getTableName(); + $tableName = $record->getTable()->getTableName(); + $identifier = $record->getTable()->getIdentifier(); + + $sub = "SELECT ".$this->getForeign(). + " FROM ".$assocTable. + " WHERE ".$this->getLocal(). + " = ?"; + + $sub2 = "SELECT ".$this->getLocal(). + " FROM ".$assocTable. + " WHERE ".$this->getForeign(). + " = ?"; + + $q->select('{'.$tableName.'.*}, {'.$assocTable.'.*}') + ->from($tableName.' INNER JOIN '.$assocTable.' ON '. + $tableName.'.'.$identifier.' = '.$assocTable.'.'.$this->getLocal().' OR '. + $tableName.'.'.$identifier.' = '.$assocTable.'.'.$this->getForeign() + ) + ->where($tableName.'.'.$identifier.' IN ('.$sub.') OR '. + $tableName.'.'.$identifier.' IN ('.$sub2.')' + ); + $q->addComponent($tableName, $record->getTable()->getComponentName()); + $q->addComponent($assocTable, $record->getTable()->getComponentName(). '.' . $this->getAssociationFactory()->getComponentName()); + + return $q->execute(array($id, $id)); + } +} +?> diff --git a/lib/Doctrine/Relation/ForeignKey.php b/lib/Doctrine/Relation/ForeignKey.php new file mode 100644 index 000000000..1de724a61 --- /dev/null +++ b/lib/Doctrine/Relation/ForeignKey.php @@ -0,0 +1,64 @@ +. + */ +Doctrine::autoload('Doctrine_Relation'); +/** + * Doctrine_Relation_ForeignKey + * This class represents a foreign key relation + * + * @author Konsta Vesterinen + * @license LGPL + * @package Doctrine + */ +class Doctrine_Relation_ForeignKey extends Doctrine_Relation { + /** + * fetchRelatedFor + * + * fetches a component related to given record + * + * @param Doctrine_Record $record + * @return Doctrine_Record|Doctrine_Collection + */ + public function fetchRelatedFor(Doctrine_Record $record) { + $id = $record->get($this->local); + + if($this->isOneToOne()) { + if(empty($id)) { + $related = $this->table->create(); + } else { + $dql = "FROM ".$this->table->getComponentName()." WHERE ".$this->table->getComponentName().".".$this->foreign." = ?"; + $coll = $this->table->getConnection()->query($dql, array($id)); + $related = $coll[0]; + } + + $related->set($this->foreign, $record, false); + + } else { + if(empty($id)) { + $related = new Doctrine_Collection($this->table); + } else { + $query = $this->getRelationDql(1); + $related = $this->table->getConnection()->query($query, array($id)); + } + $related->setReference($record, $this); + } + return $related; + } +} diff --git a/lib/Doctrine/Relation/LocalKey.php b/lib/Doctrine/Relation/LocalKey.php new file mode 100644 index 000000000..f3403709e --- /dev/null +++ b/lib/Doctrine/Relation/LocalKey.php @@ -0,0 +1,53 @@ +. + */ +Doctrine::autoload('Doctrine_Relation'); +/** + * Doctrine_Relation_LocalKey + * This class represents a local key relation + * + * @author Konsta Vesterinen + * @license LGPL + * @package Doctrine + */ +class Doctrine_Relation_LocalKey extends Doctrine_Relation { + /** + * fetchRelatedFor + * + * fetches a component related to given record + * + * @param Doctrine_Record $record + * @return Doctrine_Record|Doctrine_Collection + */ + public function fetchRelatedFor(Doctrine_Record $record) { + $id = $record->get($this->local); + + if(empty($id)) + $related = $this->table->create(); + else { + if( ! ($related = $this->table->find($id))) + $related = $this->table->create(); + } + + $record->set($this->local, $related, false); + + return $related; + } +} diff --git a/lib/Doctrine/Session.php b/lib/Doctrine/Session.php index e9c0f5c4d..4c9ef5ab3 100644 --- a/lib/Doctrine/Session.php +++ b/lib/Doctrine/Session.php @@ -274,7 +274,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab // group relations foreach($rels as $key => $rel) { - if($rel instanceof Doctrine_ForeignKey) { + if($rel instanceof Doctrine_Relation_ForeignKey) { unset($rels[$key]); array_unshift($rels, $rel); } @@ -289,7 +289,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab if($name === $nm) continue; - if($rel instanceof Doctrine_ForeignKey) { + if($rel instanceof Doctrine_Relation_ForeignKey) { if($index2 !== false) { if($index2 >= $index) continue; @@ -305,7 +305,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab //print "$k -- adding $nm :$name...
"; } - } elseif($rel instanceof Doctrine_LocalKey) { + } elseif($rel instanceof Doctrine_Relation_LocalKey) { if($index2 !== false) { if($index2 <= $index) continue; @@ -322,7 +322,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab //print "$k -- pushing $name into 0...
"; } - } elseif($rel instanceof Doctrine_Association) { + } elseif($rel instanceof Doctrine_Relation_Association) { $t = $rel->getAssociationFactory(); $n = $t->getComponentName(); @@ -715,8 +715,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab $saveLater = array(); foreach($record->getReferences() as $k=>$v) { $fk = $record->getTable()->getRelation($k); - if($fk instanceof Doctrine_ForeignKey || - $fk instanceof Doctrine_LocalKey) { + if($fk instanceof Doctrine_Relation_ForeignKey || + $fk instanceof Doctrine_Relation_LocalKey) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: @@ -744,7 +744,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab } break; endswitch; - } elseif($fk instanceof Doctrine_Association) { + } elseif($fk instanceof Doctrine_Relation_Association) { $v->save(); } } diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index c57b3db41..93be6fb34 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -609,7 +609,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { if( ! isset($local)) $local = $table->getIdentifier(); - $relation = new Doctrine_LocalKey($table,$foreign,$local,$type, $alias); + $relation = new Doctrine_Relation_LocalKey($table,$foreign,$local,$type, $alias); } else throw new Doctrine_Table_Exception("Only one-to-one relations are possible when local reference key is used."); @@ -620,7 +620,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $local = $this->identifier; // ONE-TO-MANY or ONE-TO-ONE - $relation = new Doctrine_ForeignKey($table, $local, $foreign, $type, $alias); + $relation = new Doctrine_Relation_ForeignKey($table, $local, $foreign, $type, $alias); } else { // MANY-TO-MANY @@ -651,9 +651,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { if(count($fields) > 1) { // SELF-REFERENCING THROUGH JOIN TABLE - $this->relations[$e2[0]] = new Doctrine_ForeignKey($associationTable,$local,$fields[0],Doctrine_Relation::MANY_COMPOSITE, $e2[0]); + $this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($associationTable,$local,$fields[0],Doctrine_Relation::MANY_COMPOSITE, $e2[0]); - $relation = new Doctrine_Association_Self($table,$associationTable,$fields[0],$fields[1], $type, $alias); + $relation = new Doctrine_Relation_Association_Self($table,$associationTable,$fields[0],$fields[1], $type, $alias); } else { // auto initialize a new one-to-one relationship for association table @@ -661,9 +661,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $associationTable->bind($table->getComponentName(), $associationTable->getComponentName(). '.' .$foreign, Doctrine_Relation::ONE_AGGREGATE, 'id'); // NORMAL MANY-TO-MANY RELATIONSHIP - $this->relations[$e2[0]] = new Doctrine_ForeignKey($associationTable,$local,$e2[1],Doctrine_Relation::MANY_COMPOSITE, $e2[0]); + $this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($associationTable,$local,$e2[1],Doctrine_Relation::MANY_COMPOSITE, $e2[0]); - $relation = new Doctrine_Association($table, $associationTable, $e2[1], $foreign, $type, $alias); + $relation = new Doctrine_Relation_Association($table, $associationTable, $e2[1], $foreign, $type, $alias); } }