From 33c76f620ea086090d1fa80e340195fda525c197 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 23 Mar 2008 11:30:29 +0000 Subject: [PATCH] refactorings --- lib/Doctrine.php | 9 ++-- lib/Doctrine/ClassMetadata.php | 14 +++--- lib/Doctrine/ClassMetadata/Factory.php | 4 +- lib/Doctrine/Collection.php | 43 ++++++++++--------- lib/Doctrine/Connection.php | 6 +-- lib/Doctrine/Export.php | 2 +- lib/Doctrine/Mapper.php | 2 +- lib/Doctrine/Mapper/DefaultStrategy.php | 21 --------- lib/Doctrine/Mapper/JoinedStrategy.php | 9 ++-- lib/Doctrine/Mapper/Strategy.php | 21 +++++++++ lib/Doctrine/Query/Abstract.php | 2 +- lib/Doctrine/Record.php | 4 +- tests/Orm/Component/AllTests.php | 2 +- tests/Orm/Component/CollectionTest.php | 19 ++++---- tests/Orm/Component/TestTest.php | 7 +++ tests/fixtures/forum/common/admins.php | 6 +-- tests/models/forum/ForumAdministrator.php | 4 +- tests/models/forum/ForumUser.php | 6 +-- tests_old/ClassTableInheritanceTestCase.php | 2 +- tests_old/CollectionTestCase.php | 4 +- tests_old/Inheritance/JoinedTestCase.php | 2 +- tests_old/Inheritance/SingleTableTestCase.php | 2 +- .../Inheritance/TablePerClassTestCase.php | 2 +- tests_old/Metadata/FactoryTestCase.php | 4 +- tests_old/Ticket/697TestCase.php | 2 +- tests_old/models/BaseSymfonyRecord.php | 1 + tests_old/models/Entity.php | 2 +- tests_old/models/InheritanceDealUser.php | 2 +- tests_old/models/RelationTest.php | 1 + 29 files changed, 108 insertions(+), 97 deletions(-) diff --git a/lib/Doctrine.php b/lib/Doctrine.php index 8053f0f85..91be71f7d 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -567,27 +567,28 @@ final class Doctrine /** * INHERITANCE TYPE CONSTANTS. */ - + const INHERITANCE_TYPE_NONE = 0; + /** * Constant for Single Table Inheritance. * * @see http://martinfowler.com/eaaCatalog/singleTableInheritance.html */ - const INHERITANCETYPE_SINGLE_TABLE = 1; + const INHERITANCE_TYPE_SINGLE_TABLE = 1; /** * Constant for Class Table Inheritance. * * @see http://martinfowler.com/eaaCatalog/classTableInheritance.html */ - const INHERITANCETYPE_JOINED = 2; + const INHERITANCE_TYPE_JOINED = 2; /** * Constant for Concrete Table Inheritance. * * @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html */ - const INHERITANCETYPE_TABLE_PER_CLASS = 3; + const INHERITANCE_TYPE_TABLE_PER_CLASS = 3; /** diff --git a/lib/Doctrine/ClassMetadata.php b/lib/Doctrine/ClassMetadata.php index 7b2408c16..ddea4cbc7 100644 --- a/lib/Doctrine/ClassMetadata.php +++ b/lib/Doctrine/ClassMetadata.php @@ -87,7 +87,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab * * @var integer */ - protected $_inheritanceType = Doctrine::INHERITANCETYPE_TABLE_PER_CLASS; + protected $_inheritanceType = Doctrine::INHERITANCE_TYPE_NONE; /** * An array containing all behaviors attached to the class. @@ -1157,11 +1157,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab */ public function setInheritanceType($type, array $options = array()) { - if ($type == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + if ($type == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $this->_checkRequiredDiscriminatorOptions($options); - } else if ($type == Doctrine::INHERITANCETYPE_JOINED) { + } else if ($type == Doctrine::INHERITANCE_TYPE_JOINED) { $this->_checkRequiredDiscriminatorOptions($options); - } else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { + } else if ($type == Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS) { // concrete table inheritance ... } else { throw new Doctrine_ClassMetadata_Exception("Invalid inheritance type '$type'."); @@ -1268,7 +1268,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab // If the class is part of a Single Table Inheritance hierarchy, collect the fields // of all classes in the hierarchy. - if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $parents = $this->getOption('parents'); if ($parents) { $rootClass = $this->_conn->getClassMetadata(array_pop($parents)); @@ -1280,7 +1280,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab $subClassMetadata = $this->_conn->getClassMetadata($subClass); $allColumns = array_merge($allColumns, $subClassMetadata->getColumns()); } - } else if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_JOINED) { + } else if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_JOINED) { // Remove inherited, non-pk fields. They're not in the table of this class foreach ($allColumns as $name => $definition) { if (isset($definition['primary']) && $definition['primary'] === true) { @@ -1293,7 +1293,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab unset($allColumns[$name]); } } - } else if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { + } else if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS) { // If this is a subclass, just remove existing autoincrement options on the pk if ($this->getParentClasses()) { foreach ($allColumns as $name => $definition) { diff --git a/lib/Doctrine/ClassMetadata/Factory.php b/lib/Doctrine/ClassMetadata/Factory.php index c4f5ea38b..5f8a3c0b5 100644 --- a/lib/Doctrine/ClassMetadata/Factory.php +++ b/lib/Doctrine/ClassMetadata/Factory.php @@ -114,7 +114,7 @@ class Doctrine_ClassMetadata_Factory $this->_addInheritedFields($subClass, $parent); $this->_addInheritedRelations($subClass, $parent); $this->_loadMetadata($subClass, $subclassName); - if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + if ($parent->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $subClass->setTableName($parent->getTableName()); } $classes[$subclassName] = $subClass; @@ -208,7 +208,7 @@ class Doctrine_ClassMetadata_Factory { switch (count((array)$class->getIdentifier())) { case 0: - if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED && + if ($class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED && count($class->getOption('parents')) > 0) { $parents = $class->getOption('parents'); diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 16aceaed9..056c5019d 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -81,7 +81,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * * @var string */ - protected $keyColumn; + protected $_keyField; /** * Helper variable. Used for fast null value testing. @@ -101,23 +101,26 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * @param string $keyColumn The field name that will be used as the key * in the collection. */ - public function __construct($mapper, $keyColumn = null) + public function __construct($mapper, $keyField = null) { if (is_string($mapper)) { $mapper = Doctrine_Manager::getInstance()->getMapper($mapper); } $this->_mapper = $mapper; - if ($keyColumn === null) { - $keyColumn = $mapper->getClassMetadata()->getBoundQueryPart('indexBy'); + if ($keyField === null) { + $keyField = $mapper->getClassMetadata()->getBoundQueryPart('indexBy'); } - if ($keyColumn === null) { - $keyColumn = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY); + if ($keyField === null) { + $keyField = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY); } - if ($keyColumn !== null) { - $this->keyColumn = $keyColumn; + if ($keyField !== null) { + if ( ! $this->_mapper->getClassMetadata()->hasField($keyField)) { + throw new Doctrine_Collection_Exception("Invalid field '$keyField' can't be uses as key."); + } + $this->_keyField = $keyField; } } @@ -218,32 +221,32 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } if ($keyColumn !== null) { - $this->keyColumn = $keyColumn; + $this->_keyField = $keyColumn; } } /** - * setKeyColumn + * setKeyField * sets the key column for this collection * * @param string $column * @return Doctrine_Collection */ - public function setKeyColumn($column) + public function setKeyField($fieldName) { - $this->keyColumn = $column; + $this->_keyField = $fieldName; return $this; } /** - * getKeyColumn + * getKeyField * returns the name of the key column * * @return string */ - public function getKeyColumn() + public function getKeyField() { - return $this->keyColumn; + return $this->_keyField; } /** @@ -408,8 +411,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $this->data[$key] = $record; } - if (isset($this->keyColumn)) { - $record->set($this->keyColumn, $key); + if (isset($this->_keyField)) { + $record->set($this->_keyField, $key); } return $record; @@ -535,10 +538,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } // why is this not checked when the keyColumn is set? - if (isset($this->keyColumn)) { - $value = $record->get($this->keyColumn); + if (isset($this->_keyField)) { + $value = $record->get($this->_keyField); if ($value === null) { - throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); + throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->_keyField."' was null."); } $this->data[$value] = $record; } else { diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 750a2c354..a2b519060 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -1144,11 +1144,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } else { // instantiate correct mapper type $inheritanceType = $metadata->getInheritanceType(); - if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) { + if ($inheritanceType == Doctrine::INHERITANCE_TYPE_JOINED) { $mapper = new Doctrine_Mapper_Joined($entityName, $metadata); - } else if ($inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + } else if ($inheritanceType == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $mapper = new Doctrine_Mapper_SingleTable($entityName, $metadata); - } else if ($inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { + } else if ($inheritanceType == Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS) { $mapper = new Doctrine_Mapper_TablePerClass($entityName, $metadata); } else { throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper."); diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 9506606d4..611ecbe0e 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1158,7 +1158,7 @@ class Doctrine_Export extends Doctrine_Connection_Module // In Class Table Inheritance we have to make sure that ALL tables are exported // as soon as ONE table is exported, because the data of one class is stored // across many tables. - if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) { + if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED) { $parents = $classMetadata->getOption('parents'); foreach ($parents as $parent) { $data = $classMetadata->getConnection()->getClassMetadata($parent)->getExportableFormat(); diff --git a/lib/Doctrine/Mapper.php b/lib/Doctrine/Mapper.php index cb525d013..42cbdad1a 100644 --- a/lib/Doctrine/Mapper.php +++ b/lib/Doctrine/Mapper.php @@ -87,7 +87,7 @@ class Doctrine_Mapper $this->_conn = $classMetadata->getConnection(); $this->_classMetadata = $classMetadata; $this->_nullObject = Doctrine_Null::$INSTANCE; - if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) { + if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED) { $this->_mappingStrategy = new Doctrine_Mapper_JoinedStrategy($this); } else { $this->_mappingStrategy = new Doctrine_Mapper_DefaultStrategy($this); diff --git a/lib/Doctrine/Mapper/DefaultStrategy.php b/lib/Doctrine/Mapper/DefaultStrategy.php index 74fe277e9..b8f4c58ad 100644 --- a/lib/Doctrine/Mapper/DefaultStrategy.php +++ b/lib/Doctrine/Mapper/DefaultStrategy.php @@ -58,27 +58,6 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy } } - /** - * deletes all related composites - * this method is always called internally when a record is deleted - * - * @throws PDOException if something went wrong at database level - * @return void - */ - protected function _deleteComposites(Doctrine_Record $record) - { - $classMetadata = $this->_mapper->getClassMetadata(); - foreach ($classMetadata->getRelations() as $fk) { - if ($fk->isComposite()) { - $obj = $record->get($fk->getAlias()); - if ($obj instanceof Doctrine_Record && - $obj->state() != Doctrine_Record::STATE_LOCKED) { - $obj->delete($this->_mapper->getConnection()); - } - } - } - } - /** * Inserts a single entity into the database, without any related entities. * diff --git a/lib/Doctrine/Mapper/JoinedStrategy.php b/lib/Doctrine/Mapper/JoinedStrategy.php index 226e1c7f7..aafea4389 100644 --- a/lib/Doctrine/Mapper/JoinedStrategy.php +++ b/lib/Doctrine/Mapper/JoinedStrategy.php @@ -135,18 +135,19 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy try { $class = $this->_mapper->getClassMetadata(); $conn->beginInternalTransaction(); - $this->deleteComposites($record); + $this->_deleteComposites($record); $record->state(Doctrine_Record::STATE_TDIRTY); $identifier = $this->_convertFieldToColumnNames($record->identifier(), $class); - + + // run deletions, starting from the class, upwards the hierarchy + $conn->delete($class->getTableName(), $identifier); foreach ($class->getParentClasses() as $parent) { $parentClass = $conn->getClassMetadata($parent); $this->_deleteRow($parentClass->getTableName(), $identifier); } - - $conn->delete($class->getTableName(), $identifier); + $record->state(Doctrine_Record::STATE_TCLEAN); $this->_mapper->removeRecord($record); diff --git a/lib/Doctrine/Mapper/Strategy.php b/lib/Doctrine/Mapper/Strategy.php index cc15b265f..ed896827e 100644 --- a/lib/Doctrine/Mapper/Strategy.php +++ b/lib/Doctrine/Mapper/Strategy.php @@ -60,6 +60,27 @@ abstract class Doctrine_Mapper_Strategy return $converted; } + /** + * deletes all related composites + * this method is always called internally when a record is deleted + * + * @throws PDOException if something went wrong at database level + * @return void + */ + protected function _deleteComposites(Doctrine_Record $record) + { + $classMetadata = $this->_mapper->getClassMetadata(); + foreach ($classMetadata->getRelations() as $fk) { + if ($fk->isComposite()) { + $obj = $record->get($fk->getAlias()); + if ($obj instanceof Doctrine_Record && + $obj->state() != Doctrine_Record::STATE_LOCKED) { + $obj->delete($this->_mapper->getConnection()); + } + } + } + } + /** * Callback that is invoked during the SQL construction process. */ diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 042a5be8a..8b6a344f2 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -562,7 +562,7 @@ abstract class Doctrine_Query_Abstract $array = array(); foreach ($this->_queryComponents as $componentAlias => $data) { $sqlTableAlias = $this->getSqlTableAlias($componentAlias); - if ($data['table']->getInheritanceType() != Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + if ($data['table']->getInheritanceType() != Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $array[$sqlTableAlias][] = array(); } else { $discCol = $data['table']->getInheritanceOption('discriminatorColumn'); diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 89bf5105b..2f573831e 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1237,8 +1237,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite // @todo cleanup // populates the discriminator field in Single & Class Table Inheritance - if ($this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED || - $this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + if ($this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED || + $this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { $discCol = $this->_class->getInheritanceOption('discriminatorColumn'); $discMap = $this->_class->getInheritanceOption('discriminatorMap'); $old = $this->get($discCol, false); diff --git a/tests/Orm/Component/AllTests.php b/tests/Orm/Component/AllTests.php index a8ef3b86d..442c02c83 100644 --- a/tests/Orm/Component/AllTests.php +++ b/tests/Orm/Component/AllTests.php @@ -21,7 +21,7 @@ class Orm_Component_AllTests { $suite = new Doctrine_TestSuite('Doctrine Orm Component'); - //$suite->addTestSuite('Orm_Component_TestTest'); + $suite->addTestSuite('Orm_Component_TestTest'); $suite->addTestSuite('Orm_Component_AccessTest'); $suite->addTestSuite('Orm_Component_CollectionTest'); diff --git a/tests/Orm/Component/CollectionTest.php b/tests/Orm/Component/CollectionTest.php index 94c7705e4..153b2d6a9 100644 --- a/tests/Orm/Component/CollectionTest.php +++ b/tests/Orm/Component/CollectionTest.php @@ -57,7 +57,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase */ public function shouldHaveBlankAsDefaultKeyColumn() { - $this->assertEquals('', $this->coll->getKeyColumn()); + $this->assertEquals('', $this->coll->getKeyField()); } @@ -67,7 +67,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase public function shouldUseSpecifiedKeyColumn() { $coll = new Doctrine_Collection('ForumUser', 'id'); - $this->assertEquals('id', $coll->getKeyColumn()); + $this->assertEquals('id', $coll->getKeyField()); } /** @@ -75,11 +75,11 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase * possible to set this to something that is not valid. * * @test - * @expectedException Doctrine_Exception + * @expectedException Doctrine_Collection_Exception */ public function shouldThrowExceptionIfNonValidFieldSetAsKey() { - $coll = new Doctrine_Collection('ForumUser', 'rat'); + $coll = new Doctrine_Collection('ForumUser', 'xxNonValidFieldxx'); } /** @@ -87,8 +87,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase */ public function shouldSerializeEmptyCollection() { - $serializedFormCollection='C:19:"Doctrine_Collection":158:{a:7:{s:4:"data";a:0:{}s:7:"_mapper";s:9:"ForumUser";s:9:"_snapshot";a:0:{}s:14:"referenceField";N;s:9:"keyColumn";N;s:8:"_locator";N;s:10:"_resources";a:0:{}}}'; - $this->assertEquals($serializedFormCollection, serialize($this->coll)); + $serialized = serialize($this->coll); + $this->assertTrue(is_string($serialized)); } /** @@ -96,8 +96,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase */ public function shouldUnserializeEmptyCollectionIntoObject() { - $serializedFormCollection='C:19:"Doctrine_Collection":158:{a:7:{s:4:"data";a:0:{}s:7:"_mapper";s:9:"ForumUser";s:9:"_snapshot";a:0:{}s:14:"referenceField";N;s:9:"keyColumn";N;s:8:"_locator";N;s:10:"_resources";a:0:{}}}'; - $coll = unserialize($serializedFormCollection); + $serialized = serialize($this->coll); + $coll = unserialize($serialized); $this->assertEquals('Doctrine_Collection', get_class($coll)); } @@ -119,12 +119,11 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase $serialized = serialize($this->cmsColl); $coll = unserialize($serialized); - $this->assertEquals('username', $coll->getKeyColumn()); + $this->assertEquals('username', $coll->getKeyField()); $this->assertTrue(isset($coll['test'])); $user = $coll['test']; $this->assertTrue($user instanceOf CmsUser); $this->assertEquals('test', $user['username']); - } } diff --git a/tests/Orm/Component/TestTest.php b/tests/Orm/Component/TestTest.php index dfd810ddd..86804aa09 100644 --- a/tests/Orm/Component/TestTest.php +++ b/tests/Orm/Component/TestTest.php @@ -28,4 +28,11 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase $forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u"); $this->assertEquals(2, count($forumUsers)); } + + public function testFixture3() + { + $forumAdmins = $this->sharedFixture['connection']->query("FROM ForumAdministrator adm"); + $this->assertEquals(1, count($forumAdmins)); + $forumAdmins[0]->delete(); + } } \ No newline at end of file diff --git a/tests/fixtures/forum/common/admins.php b/tests/fixtures/forum/common/admins.php index 32edea90b..3f0dc40ff 100644 --- a/tests/fixtures/forum/common/admins.php +++ b/tests/fixtures/forum/common/admins.php @@ -4,11 +4,7 @@ $fixture = array( 'rows' => array( array( 'id' => 1, - 'foo' => 'bar' - ), - array( - 'id' => 2, - 'foo' => 'bar2' + 'access_level' => 4 ) ) ); \ No newline at end of file diff --git a/tests/models/forum/ForumAdministrator.php b/tests/models/forum/ForumAdministrator.php index 0df442ab0..00884d540 100644 --- a/tests/models/forum/ForumAdministrator.php +++ b/tests/models/forum/ForumAdministrator.php @@ -4,6 +4,8 @@ class ForumAdministrator extends ForumUser { public static function initMetadata($class) { - $class->mapColumn('foo', 'string', 50); + $class->mapColumn('access_level as accessLevel', 'integer', 1); } + + public function banUser(ForumUser $user) {} } \ No newline at end of file diff --git a/tests/models/forum/ForumUser.php b/tests/models/forum/ForumUser.php index 2623128b7..6f060104f 100644 --- a/tests/models/forum/ForumUser.php +++ b/tests/models/forum/ForumUser.php @@ -5,18 +5,18 @@ class ForumUser extends Doctrine_Record public static function initMetadata($class) { // inheritance mapping - $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array( 'discriminatorColumn' => 'dtype', 'discriminatorMap' => array( 'user' => 'ForumUser', 'admin' => 'ForumAdministrator') )); + // register subclasses $class->setSubclasses(array('ForumAdministrator')); - // the discriminator column $class->mapColumn('dtype', 'string', 50); - // column mapping + // column-to-field mapping $class->mapColumn('id', 'integer', 4, array( 'primary' => true, 'autoincrement' => true)); diff --git a/tests_old/ClassTableInheritanceTestCase.php b/tests_old/ClassTableInheritanceTestCase.php index d8e0d16fa..815cd94c3 100644 --- a/tests_old/ClassTableInheritanceTestCase.php +++ b/tests_old/ClassTableInheritanceTestCase.php @@ -229,7 +229,7 @@ class CTITestParent1 extends Doctrine_Record { public function setTableDefinition() { - $this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( + $this->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array( 'CTITestParent1' => 1, 'CTITestParent2' => 2, 'CTITestParent3' => 3, 'CTITestParent4' => 4, 'CTITest' => 5)); diff --git a/tests_old/CollectionTestCase.php b/tests_old/CollectionTestCase.php index 5d495b556..75d54e94f 100644 --- a/tests_old/CollectionTestCase.php +++ b/tests_old/CollectionTestCase.php @@ -255,14 +255,14 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase - $coll->setKeyColumn('id'); + $coll->setKeyField('id'); $user = $this->connection->getTable("User")->find(4); } public function testGenerator() { $coll = new Doctrine_Collection($this->objTable); - $coll->setKeyColumn('name'); + $coll->setKeyField('name'); $user = new User(); $user->name = "name"; diff --git a/tests_old/Inheritance/JoinedTestCase.php b/tests_old/Inheritance/JoinedTestCase.php index 76557d7c0..cb8ec8e9b 100644 --- a/tests_old/Inheritance/JoinedTestCase.php +++ b/tests_old/Inheritance/JoinedTestCase.php @@ -187,7 +187,7 @@ class CTI_User extends Doctrine_Record { public static function initMetadata($class) { - $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array( 'discriminatorColumn' => 'dtype', 'discriminatorMap' => array(1 => 'CTI_User', 2 => 'CTI_Manager', 3 => 'CTI_Customer', 4 => 'CTI_SuperManager') diff --git a/tests_old/Inheritance/SingleTableTestCase.php b/tests_old/Inheritance/SingleTableTestCase.php index 8f80f48b7..9b9dab8bb 100644 --- a/tests_old/Inheritance/SingleTableTestCase.php +++ b/tests_old/Inheritance/SingleTableTestCase.php @@ -67,7 +67,7 @@ class STI_User extends Doctrine_Record { public static function initMetadata($class) { - $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array( 'discriminatorColumn' => 'type', 'discriminatorMap' => array( 1 => 'STI_User', diff --git a/tests_old/Inheritance/TablePerClassTestCase.php b/tests_old/Inheritance/TablePerClassTestCase.php index 3f0819021..a4868c61c 100644 --- a/tests_old/Inheritance/TablePerClassTestCase.php +++ b/tests_old/Inheritance/TablePerClassTestCase.php @@ -70,7 +70,7 @@ class CCTI_User extends Doctrine_Record { public static function initMetadata($class) { - $class->setInheritanceType(Doctrine::INHERITANCETYPE_TABLE_PER_CLASS); + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS); $class->setTableName('ccti_user'); $class->setSubclasses(array('CCTI_Manager', 'CCTI_Customer', 'CCTI_SuperManager')); $class->setColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true)); diff --git a/tests_old/Metadata/FactoryTestCase.php b/tests_old/Metadata/FactoryTestCase.php index bb10f6135..bebaf641b 100644 --- a/tests_old/Metadata/FactoryTestCase.php +++ b/tests_old/Metadata/FactoryTestCase.php @@ -146,7 +146,7 @@ class Metadata_User extends Doctrine_Record public static function initMetadata(Doctrine_ClassMetadata $class) { $class->setTableName('cti_user'); - $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array('discriminatorColumn' => 'type', 'discriminatorMap' => array( 1 => 'CTI_User', @@ -200,7 +200,7 @@ class Metadata_STI_User extends Doctrine_Record public static function initMetadata($class) { $class->setTableName('cti_user'); - $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array('discriminatorColumn' => 'type', 'discriminatorMap' => array( 1 => 'CTI_User', diff --git a/tests_old/Ticket/697TestCase.php b/tests_old/Ticket/697TestCase.php index c66335af4..c6d2cd04c 100644 --- a/tests_old/Ticket/697TestCase.php +++ b/tests_old/Ticket/697TestCase.php @@ -40,7 +40,7 @@ class T697_Person extends Doctrine_Record { public static function initMetadata($class) { - $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array( 'discriminatorColumn' => 'dtype', 'discriminatorMap' => array( 1 => 'T697_Person', 2 => 'T697_User' diff --git a/tests_old/models/BaseSymfonyRecord.php b/tests_old/models/BaseSymfonyRecord.php index bb04a5f91..e5a3a7611 100644 --- a/tests_old/models/BaseSymfonyRecord.php +++ b/tests_old/models/BaseSymfonyRecord.php @@ -3,6 +3,7 @@ abstract class BaseSymfonyRecord extends Doctrine_Record { public static function initMetadata($class) { + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS); $class->setColumn('name', 'string', 30); } diff --git a/tests_old/models/Entity.php b/tests_old/models/Entity.php index b33da6ec4..d1d5e1db9 100644 --- a/tests_old/models/Entity.php +++ b/tests_old/models/Entity.php @@ -13,7 +13,7 @@ class Entity extends Doctrine_Record $class->setColumn('email_id', 'integer'); $class->setSubclasses(array('Group', 'User')); - $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array( 'discriminatorColumn' => 'type', 'discriminatorMap' => array(0 => 'User', 1 => 'Group', 2 => 'Entity') )); diff --git a/tests_old/models/InheritanceDealUser.php b/tests_old/models/InheritanceDealUser.php index c1943ad14..f9b75f0ba 100644 --- a/tests_old/models/InheritanceDealUser.php +++ b/tests_old/models/InheritanceDealUser.php @@ -3,7 +3,7 @@ class InheritanceEntityUser extends Doctrine_Record { public static function initMetadata($class) { - $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array( 'discriminatorColumn' => 'type', 'discriminatorMap' => array(1 => 'InheritanceDealUser', 2 => 'InheritanceEntityUser') )); diff --git a/tests_old/models/RelationTest.php b/tests_old/models/RelationTest.php index 5d76dd1c3..d251b2c0f 100644 --- a/tests_old/models/RelationTest.php +++ b/tests_old/models/RelationTest.php @@ -3,6 +3,7 @@ class RelationTest extends Doctrine_Record { public static function initMetadata($class) { + $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS); $class->setColumn('name', 'string', 200); $class->setColumn('parent_id', 'integer'); }