Commit 33c76f62 authored by romanb's avatar romanb

refactorings

parent 7a1beb5b
...@@ -567,27 +567,28 @@ final class Doctrine ...@@ -567,27 +567,28 @@ final class Doctrine
/** /**
* INHERITANCE TYPE CONSTANTS. * INHERITANCE TYPE CONSTANTS.
*/ */
const INHERITANCE_TYPE_NONE = 0;
/** /**
* Constant for Single Table Inheritance. * Constant for Single Table Inheritance.
* *
* @see http://martinfowler.com/eaaCatalog/singleTableInheritance.html * @see http://martinfowler.com/eaaCatalog/singleTableInheritance.html
*/ */
const INHERITANCETYPE_SINGLE_TABLE = 1; const INHERITANCE_TYPE_SINGLE_TABLE = 1;
/** /**
* Constant for Class Table Inheritance. * Constant for Class Table Inheritance.
* *
* @see http://martinfowler.com/eaaCatalog/classTableInheritance.html * @see http://martinfowler.com/eaaCatalog/classTableInheritance.html
*/ */
const INHERITANCETYPE_JOINED = 2; const INHERITANCE_TYPE_JOINED = 2;
/** /**
* Constant for Concrete Table Inheritance. * Constant for Concrete Table Inheritance.
* *
* @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html * @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html
*/ */
const INHERITANCETYPE_TABLE_PER_CLASS = 3; const INHERITANCE_TYPE_TABLE_PER_CLASS = 3;
/** /**
......
...@@ -87,7 +87,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -87,7 +87,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @var integer * @var integer
*/ */
protected $_inheritanceType = Doctrine::INHERITANCETYPE_TABLE_PER_CLASS; protected $_inheritanceType = Doctrine::INHERITANCE_TYPE_NONE;
/** /**
* An array containing all behaviors attached to the class. * An array containing all behaviors attached to the class.
...@@ -1157,11 +1157,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1157,11 +1157,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function setInheritanceType($type, array $options = array()) public function setInheritanceType($type, array $options = array())
{ {
if ($type == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { if ($type == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) {
$this->_checkRequiredDiscriminatorOptions($options); $this->_checkRequiredDiscriminatorOptions($options);
} else if ($type == Doctrine::INHERITANCETYPE_JOINED) { } else if ($type == Doctrine::INHERITANCE_TYPE_JOINED) {
$this->_checkRequiredDiscriminatorOptions($options); $this->_checkRequiredDiscriminatorOptions($options);
} else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { } else if ($type == Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS) {
// concrete table inheritance ... // concrete table inheritance ...
} else { } else {
throw new Doctrine_ClassMetadata_Exception("Invalid inheritance type '$type'."); throw new Doctrine_ClassMetadata_Exception("Invalid inheritance type '$type'.");
...@@ -1268,7 +1268,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -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 // If the class is part of a Single Table Inheritance hierarchy, collect the fields
// of all classes in the hierarchy. // 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'); $parents = $this->getOption('parents');
if ($parents) { if ($parents) {
$rootClass = $this->_conn->getClassMetadata(array_pop($parents)); $rootClass = $this->_conn->getClassMetadata(array_pop($parents));
...@@ -1280,7 +1280,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1280,7 +1280,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$subClassMetadata = $this->_conn->getClassMetadata($subClass); $subClassMetadata = $this->_conn->getClassMetadata($subClass);
$allColumns = array_merge($allColumns, $subClassMetadata->getColumns()); $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 // Remove inherited, non-pk fields. They're not in the table of this class
foreach ($allColumns as $name => $definition) { foreach ($allColumns as $name => $definition) {
if (isset($definition['primary']) && $definition['primary'] === true) { if (isset($definition['primary']) && $definition['primary'] === true) {
...@@ -1293,7 +1293,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1293,7 +1293,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
unset($allColumns[$name]); 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 is a subclass, just remove existing autoincrement options on the pk
if ($this->getParentClasses()) { if ($this->getParentClasses()) {
foreach ($allColumns as $name => $definition) { foreach ($allColumns as $name => $definition) {
......
...@@ -114,7 +114,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -114,7 +114,7 @@ class Doctrine_ClassMetadata_Factory
$this->_addInheritedFields($subClass, $parent); $this->_addInheritedFields($subClass, $parent);
$this->_addInheritedRelations($subClass, $parent); $this->_addInheritedRelations($subClass, $parent);
$this->_loadMetadata($subClass, $subclassName); $this->_loadMetadata($subClass, $subclassName);
if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { if ($parent->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) {
$subClass->setTableName($parent->getTableName()); $subClass->setTableName($parent->getTableName());
} }
$classes[$subclassName] = $subClass; $classes[$subclassName] = $subClass;
...@@ -208,7 +208,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -208,7 +208,7 @@ class Doctrine_ClassMetadata_Factory
{ {
switch (count((array)$class->getIdentifier())) { switch (count((array)$class->getIdentifier())) {
case 0: case 0:
if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED && if ($class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED &&
count($class->getOption('parents')) > 0) { count($class->getOption('parents')) > 0) {
$parents = $class->getOption('parents'); $parents = $class->getOption('parents');
......
...@@ -81,7 +81,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -81,7 +81,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @var string * @var string
*/ */
protected $keyColumn; protected $_keyField;
/** /**
* Helper variable. Used for fast null value testing. * Helper variable. Used for fast null value testing.
...@@ -101,23 +101,26 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -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 * @param string $keyColumn The field name that will be used as the key
* in the collection. * in the collection.
*/ */
public function __construct($mapper, $keyColumn = null) public function __construct($mapper, $keyField = null)
{ {
if (is_string($mapper)) { if (is_string($mapper)) {
$mapper = Doctrine_Manager::getInstance()->getMapper($mapper); $mapper = Doctrine_Manager::getInstance()->getMapper($mapper);
} }
$this->_mapper = $mapper; $this->_mapper = $mapper;
if ($keyColumn === null) { if ($keyField === null) {
$keyColumn = $mapper->getClassMetadata()->getBoundQueryPart('indexBy'); $keyField = $mapper->getClassMetadata()->getBoundQueryPart('indexBy');
} }
if ($keyColumn === null) { if ($keyField === null) {
$keyColumn = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY); $keyField = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY);
} }
if ($keyColumn !== null) { if ($keyField !== null) {
$this->keyColumn = $keyColumn; 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 ...@@ -218,32 +221,32 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
if ($keyColumn !== null) { if ($keyColumn !== null) {
$this->keyColumn = $keyColumn; $this->_keyField = $keyColumn;
} }
} }
/** /**
* setKeyColumn * setKeyField
* sets the key column for this collection * sets the key column for this collection
* *
* @param string $column * @param string $column
* @return Doctrine_Collection * @return Doctrine_Collection
*/ */
public function setKeyColumn($column) public function setKeyField($fieldName)
{ {
$this->keyColumn = $column; $this->_keyField = $fieldName;
return $this; return $this;
} }
/** /**
* getKeyColumn * getKeyField
* returns the name of the key column * returns the name of the key column
* *
* @return string * @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 ...@@ -408,8 +411,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key] = $record; $this->data[$key] = $record;
} }
if (isset($this->keyColumn)) { if (isset($this->_keyField)) {
$record->set($this->keyColumn, $key); $record->set($this->_keyField, $key);
} }
return $record; return $record;
...@@ -535,10 +538,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -535,10 +538,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
// why is this not checked when the keyColumn is set? // why is this not checked when the keyColumn is set?
if (isset($this->keyColumn)) { if (isset($this->_keyField)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->_keyField);
if ($value === null) { 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; $this->data[$value] = $record;
} else { } else {
......
...@@ -1144,11 +1144,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1144,11 +1144,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} else { } else {
// instantiate correct mapper type // instantiate correct mapper type
$inheritanceType = $metadata->getInheritanceType(); $inheritanceType = $metadata->getInheritanceType();
if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) { if ($inheritanceType == Doctrine::INHERITANCE_TYPE_JOINED) {
$mapper = new Doctrine_Mapper_Joined($entityName, $metadata); $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); $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); $mapper = new Doctrine_Mapper_TablePerClass($entityName, $metadata);
} else { } else {
throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper."); throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper.");
......
...@@ -1158,7 +1158,7 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -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 // 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 // as soon as ONE table is exported, because the data of one class is stored
// across many tables. // across many tables.
if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) { if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED) {
$parents = $classMetadata->getOption('parents'); $parents = $classMetadata->getOption('parents');
foreach ($parents as $parent) { foreach ($parents as $parent) {
$data = $classMetadata->getConnection()->getClassMetadata($parent)->getExportableFormat(); $data = $classMetadata->getConnection()->getClassMetadata($parent)->getExportableFormat();
......
...@@ -87,7 +87,7 @@ class Doctrine_Mapper ...@@ -87,7 +87,7 @@ class Doctrine_Mapper
$this->_conn = $classMetadata->getConnection(); $this->_conn = $classMetadata->getConnection();
$this->_classMetadata = $classMetadata; $this->_classMetadata = $classMetadata;
$this->_nullObject = Doctrine_Null::$INSTANCE; $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); $this->_mappingStrategy = new Doctrine_Mapper_JoinedStrategy($this);
} else { } else {
$this->_mappingStrategy = new Doctrine_Mapper_DefaultStrategy($this); $this->_mappingStrategy = new Doctrine_Mapper_DefaultStrategy($this);
......
...@@ -58,27 +58,6 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy ...@@ -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. * Inserts a single entity into the database, without any related entities.
* *
......
...@@ -135,18 +135,19 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy ...@@ -135,18 +135,19 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
try { try {
$class = $this->_mapper->getClassMetadata(); $class = $this->_mapper->getClassMetadata();
$conn->beginInternalTransaction(); $conn->beginInternalTransaction();
$this->deleteComposites($record); $this->_deleteComposites($record);
$record->state(Doctrine_Record::STATE_TDIRTY); $record->state(Doctrine_Record::STATE_TDIRTY);
$identifier = $this->_convertFieldToColumnNames($record->identifier(), $class); $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) { foreach ($class->getParentClasses() as $parent) {
$parentClass = $conn->getClassMetadata($parent); $parentClass = $conn->getClassMetadata($parent);
$this->_deleteRow($parentClass->getTableName(), $identifier); $this->_deleteRow($parentClass->getTableName(), $identifier);
} }
$conn->delete($class->getTableName(), $identifier);
$record->state(Doctrine_Record::STATE_TCLEAN); $record->state(Doctrine_Record::STATE_TCLEAN);
$this->_mapper->removeRecord($record); $this->_mapper->removeRecord($record);
......
...@@ -60,6 +60,27 @@ abstract class Doctrine_Mapper_Strategy ...@@ -60,6 +60,27 @@ abstract class Doctrine_Mapper_Strategy
return $converted; 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. * Callback that is invoked during the SQL construction process.
*/ */
......
...@@ -562,7 +562,7 @@ abstract class Doctrine_Query_Abstract ...@@ -562,7 +562,7 @@ abstract class Doctrine_Query_Abstract
$array = array(); $array = array();
foreach ($this->_queryComponents as $componentAlias => $data) { foreach ($this->_queryComponents as $componentAlias => $data) {
$sqlTableAlias = $this->getSqlTableAlias($componentAlias); $sqlTableAlias = $this->getSqlTableAlias($componentAlias);
if ($data['table']->getInheritanceType() != Doctrine::INHERITANCETYPE_SINGLE_TABLE) { if ($data['table']->getInheritanceType() != Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) {
$array[$sqlTableAlias][] = array(); $array[$sqlTableAlias][] = array();
} else { } else {
$discCol = $data['table']->getInheritanceOption('discriminatorColumn'); $discCol = $data['table']->getInheritanceOption('discriminatorColumn');
......
...@@ -1237,8 +1237,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1237,8 +1237,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// @todo cleanup // @todo cleanup
// populates the discriminator field in Single & Class Table Inheritance // populates the discriminator field in Single & Class Table Inheritance
if ($this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED || if ($this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED ||
$this->_class->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { $this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) {
$discCol = $this->_class->getInheritanceOption('discriminatorColumn'); $discCol = $this->_class->getInheritanceOption('discriminatorColumn');
$discMap = $this->_class->getInheritanceOption('discriminatorMap'); $discMap = $this->_class->getInheritanceOption('discriminatorMap');
$old = $this->get($discCol, false); $old = $this->get($discCol, false);
......
...@@ -21,7 +21,7 @@ class Orm_Component_AllTests ...@@ -21,7 +21,7 @@ class Orm_Component_AllTests
{ {
$suite = new Doctrine_TestSuite('Doctrine Orm Component'); $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_AccessTest');
$suite->addTestSuite('Orm_Component_CollectionTest'); $suite->addTestSuite('Orm_Component_CollectionTest');
......
...@@ -57,7 +57,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase ...@@ -57,7 +57,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
*/ */
public function shouldHaveBlankAsDefaultKeyColumn() public function shouldHaveBlankAsDefaultKeyColumn()
{ {
$this->assertEquals('', $this->coll->getKeyColumn()); $this->assertEquals('', $this->coll->getKeyField());
} }
...@@ -67,7 +67,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase ...@@ -67,7 +67,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
public function shouldUseSpecifiedKeyColumn() public function shouldUseSpecifiedKeyColumn()
{ {
$coll = new Doctrine_Collection('ForumUser', 'id'); $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 ...@@ -75,11 +75,11 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
* possible to set this to something that is not valid. * possible to set this to something that is not valid.
* *
* @test * @test
* @expectedException Doctrine_Exception * @expectedException Doctrine_Collection_Exception
*/ */
public function shouldThrowExceptionIfNonValidFieldSetAsKey() 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 ...@@ -87,8 +87,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
*/ */
public function shouldSerializeEmptyCollection() 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:{}}}'; $serialized = serialize($this->coll);
$this->assertEquals($serializedFormCollection, serialize($this->coll)); $this->assertTrue(is_string($serialized));
} }
/** /**
...@@ -96,8 +96,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase ...@@ -96,8 +96,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
*/ */
public function shouldUnserializeEmptyCollectionIntoObject() 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:{}}}'; $serialized = serialize($this->coll);
$coll = unserialize($serializedFormCollection); $coll = unserialize($serialized);
$this->assertEquals('Doctrine_Collection', get_class($coll)); $this->assertEquals('Doctrine_Collection', get_class($coll));
} }
...@@ -119,12 +119,11 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase ...@@ -119,12 +119,11 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
$serialized = serialize($this->cmsColl); $serialized = serialize($this->cmsColl);
$coll = unserialize($serialized); $coll = unserialize($serialized);
$this->assertEquals('username', $coll->getKeyColumn()); $this->assertEquals('username', $coll->getKeyField());
$this->assertTrue(isset($coll['test'])); $this->assertTrue(isset($coll['test']));
$user = $coll['test']; $user = $coll['test'];
$this->assertTrue($user instanceOf CmsUser); $this->assertTrue($user instanceOf CmsUser);
$this->assertEquals('test', $user['username']); $this->assertEquals('test', $user['username']);
} }
} }
...@@ -28,4 +28,11 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase ...@@ -28,4 +28,11 @@ class Orm_Component_TestTest extends Doctrine_OrmTestCase
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u"); $forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u");
$this->assertEquals(2, count($forumUsers)); $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
...@@ -4,11 +4,7 @@ $fixture = array( ...@@ -4,11 +4,7 @@ $fixture = array(
'rows' => array( 'rows' => array(
array( array(
'id' => 1, 'id' => 1,
'foo' => 'bar' 'access_level' => 4
),
array(
'id' => 2,
'foo' => 'bar2'
) )
) )
); );
\ No newline at end of file
...@@ -4,6 +4,8 @@ class ForumAdministrator extends ForumUser ...@@ -4,6 +4,8 @@ class ForumAdministrator extends ForumUser
{ {
public static function initMetadata($class) 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
...@@ -5,18 +5,18 @@ class ForumUser extends Doctrine_Record ...@@ -5,18 +5,18 @@ class ForumUser extends Doctrine_Record
public static function initMetadata($class) public static function initMetadata($class)
{ {
// inheritance mapping // inheritance mapping
$class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array(
'discriminatorColumn' => 'dtype', 'discriminatorColumn' => 'dtype',
'discriminatorMap' => array( 'discriminatorMap' => array(
'user' => 'ForumUser', 'user' => 'ForumUser',
'admin' => 'ForumAdministrator') 'admin' => 'ForumAdministrator')
)); ));
// register subclasses
$class->setSubclasses(array('ForumAdministrator')); $class->setSubclasses(array('ForumAdministrator'));
// the discriminator column // the discriminator column
$class->mapColumn('dtype', 'string', 50); $class->mapColumn('dtype', 'string', 50);
// column mapping // column-to-field mapping
$class->mapColumn('id', 'integer', 4, array( $class->mapColumn('id', 'integer', 4, array(
'primary' => true, 'primary' => true,
'autoincrement' => true)); 'autoincrement' => true));
......
...@@ -229,7 +229,7 @@ class CTITestParent1 extends Doctrine_Record ...@@ -229,7 +229,7 @@ class CTITestParent1 extends Doctrine_Record
{ {
public function setTableDefinition() public function setTableDefinition()
{ {
$this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( $this->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array(
'CTITestParent1' => 1, 'CTITestParent2' => 2, 'CTITestParent1' => 1, 'CTITestParent2' => 2,
'CTITestParent3' => 3, 'CTITestParent4' => 4, 'CTITestParent3' => 3, 'CTITestParent4' => 4,
'CTITest' => 5)); 'CTITest' => 5));
......
...@@ -255,14 +255,14 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase ...@@ -255,14 +255,14 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
$coll->setKeyColumn('id'); $coll->setKeyField('id');
$user = $this->connection->getTable("User")->find(4); $user = $this->connection->getTable("User")->find(4);
} }
public function testGenerator() public function testGenerator()
{ {
$coll = new Doctrine_Collection($this->objTable); $coll = new Doctrine_Collection($this->objTable);
$coll->setKeyColumn('name'); $coll->setKeyField('name');
$user = new User(); $user = new User();
$user->name = "name"; $user->name = "name";
......
...@@ -187,7 +187,7 @@ class CTI_User extends Doctrine_Record ...@@ -187,7 +187,7 @@ class CTI_User extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array(
'discriminatorColumn' => 'dtype', 'discriminatorColumn' => 'dtype',
'discriminatorMap' => array(1 => 'CTI_User', 2 => 'CTI_Manager', 'discriminatorMap' => array(1 => 'CTI_User', 2 => 'CTI_Manager',
3 => 'CTI_Customer', 4 => 'CTI_SuperManager') 3 => 'CTI_Customer', 4 => 'CTI_SuperManager')
......
...@@ -67,7 +67,7 @@ class STI_User extends Doctrine_Record ...@@ -67,7 +67,7 @@ class STI_User extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array(
'discriminatorColumn' => 'type', 'discriminatorColumn' => 'type',
'discriminatorMap' => array( 'discriminatorMap' => array(
1 => 'STI_User', 1 => 'STI_User',
......
...@@ -70,7 +70,7 @@ class CCTI_User extends Doctrine_Record ...@@ -70,7 +70,7 @@ class CCTI_User extends Doctrine_Record
{ {
public static function initMetadata($class) 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->setTableName('ccti_user');
$class->setSubclasses(array('CCTI_Manager', 'CCTI_Customer', 'CCTI_SuperManager')); $class->setSubclasses(array('CCTI_Manager', 'CCTI_Customer', 'CCTI_SuperManager'));
$class->setColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true)); $class->setColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true));
......
...@@ -146,7 +146,7 @@ class Metadata_User extends Doctrine_Record ...@@ -146,7 +146,7 @@ class Metadata_User extends Doctrine_Record
public static function initMetadata(Doctrine_ClassMetadata $class) public static function initMetadata(Doctrine_ClassMetadata $class)
{ {
$class->setTableName('cti_user'); $class->setTableName('cti_user');
$class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED,
array('discriminatorColumn' => 'type', array('discriminatorColumn' => 'type',
'discriminatorMap' => array( 'discriminatorMap' => array(
1 => 'CTI_User', 1 => 'CTI_User',
...@@ -200,7 +200,7 @@ class Metadata_STI_User extends Doctrine_Record ...@@ -200,7 +200,7 @@ class Metadata_STI_User extends Doctrine_Record
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setTableName('cti_user'); $class->setTableName('cti_user');
$class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE,
array('discriminatorColumn' => 'type', array('discriminatorColumn' => 'type',
'discriminatorMap' => array( 'discriminatorMap' => array(
1 => 'CTI_User', 1 => 'CTI_User',
......
...@@ -40,7 +40,7 @@ class T697_Person extends Doctrine_Record ...@@ -40,7 +40,7 @@ class T697_Person extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_JOINED, array(
'discriminatorColumn' => 'dtype', 'discriminatorColumn' => 'dtype',
'discriminatorMap' => array( 'discriminatorMap' => array(
1 => 'T697_Person', 2 => 'T697_User' 1 => 'T697_Person', 2 => 'T697_User'
......
...@@ -3,6 +3,7 @@ abstract class BaseSymfonyRecord extends Doctrine_Record ...@@ -3,6 +3,7 @@ abstract class BaseSymfonyRecord extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS);
$class->setColumn('name', 'string', 30); $class->setColumn('name', 'string', 30);
} }
......
...@@ -13,7 +13,7 @@ class Entity extends Doctrine_Record ...@@ -13,7 +13,7 @@ class Entity extends Doctrine_Record
$class->setColumn('email_id', 'integer'); $class->setColumn('email_id', 'integer');
$class->setSubclasses(array('Group', 'User')); $class->setSubclasses(array('Group', 'User'));
$class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array(
'discriminatorColumn' => 'type', 'discriminatorColumn' => 'type',
'discriminatorMap' => array(0 => 'User', 1 => 'Group', 2 => 'Entity') 'discriminatorMap' => array(0 => 'User', 1 => 'Group', 2 => 'Entity')
)); ));
......
...@@ -3,7 +3,7 @@ class InheritanceEntityUser extends Doctrine_Record ...@@ -3,7 +3,7 @@ class InheritanceEntityUser extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_SINGLE_TABLE, array(
'discriminatorColumn' => 'type', 'discriminatorColumn' => 'type',
'discriminatorMap' => array(1 => 'InheritanceDealUser', 2 => 'InheritanceEntityUser') 'discriminatorMap' => array(1 => 'InheritanceDealUser', 2 => 'InheritanceEntityUser')
)); ));
......
...@@ -3,6 +3,7 @@ class RelationTest extends Doctrine_Record ...@@ -3,6 +3,7 @@ class RelationTest extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS);
$class->setColumn('name', 'string', 200); $class->setColumn('name', 'string', 200);
$class->setColumn('parent_id', 'integer'); $class->setColumn('parent_id', 'integer');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment