From 625b6a3f82adb378381aaf79ba96f3cdfd674f32 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 26 Jun 2007 22:35:08 +0000 Subject: [PATCH] --- lib/Doctrine/Export.php | 2 +- lib/Doctrine/Relation/Parser.php | 4 +- lib/Doctrine/Table.php | 93 +------------------------------- tests/Export/RecordTestCase.php | 19 +++---- tests/run.php | 5 +- 5 files changed, 18 insertions(+), 105 deletions(-) diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index d6048c8f8..23772bb08 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1000,7 +1000,7 @@ class Doctrine_Export extends Doctrine_Connection_Module $data = $table->getExportableFormat(); $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); - + if (is_array($query)) { $sql = array_merge($sql, $query); } else { diff --git a/lib/Doctrine/Relation/Parser.php b/lib/Doctrine/Relation/Parser.php index 8e673ccab..d3854b1ab 100644 --- a/lib/Doctrine/Relation/Parser.php +++ b/lib/Doctrine/Relation/Parser.php @@ -330,9 +330,9 @@ class Doctrine_Relation_Parser } } else { if ($def['local'] !== $this->_table->getIdentifier()) { - $def['localKey'] = true; + $def['localKey'] = true; } - } + } } else { if (isset($def['foreign'])) { // local key not set, but foreign key is set diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 45f6c8477..30e72535c 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -375,111 +375,22 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable $integrity = array('onUpdate' => $fk['onUpdate'], 'onDelete' => $fk['onDelete']); - - if ($relation instanceof Doctrine_Relation_ForeignKey) { - if ($relation->getLocal() !== $relation->getTable()->getIdentifier() && - $relation->getLocal() !== $this->getIdentifier() || - $relation->hasConstraint()) { - - $def = array('local' => $relation->getLocal(), - 'foreign' => $this->getIdentifier(), - 'foreignTable' => $relation->getTable()->getTableName()); - - if (($key = array_search($def, $options['foreignKeys'])) === false) { - $options['foreignKeys'][] = $def; - - $constraints[] = $integrity; - } else { - if ($integrity !== $emptyIntegrity) { - $constraints[$key] = $integrity; - } - } - } - } elseif ($relation instanceof Doctrine_Relation_LocalKey) { - - if ($relation->getLocal() !== $this->getIdentifier() && - $relation->getForeign() !== $relation->getTable()->getIdentifier()) { - - $def = array('local' => $relation->getLocal(), - 'foreign' => $this->getIdentifier(), - 'foreignTable' => $relation->getTable()->getTableName()); - - if (($key = array_search($def, $options['foreignKeys'])) === false) { - $options['foreignKeys'][] = $def; - - $constraints[] = $integrity; - } else { - if ($integrity !== $emptyIntegrity) { - $constraints[$key] = $integrity; - } - } - } - } elseif ($relation instanceof Doctrine_Relation_Nest) { - /** + + if ($relation instanceof Doctrine_Relation_LocalKey) { $def = array('local' => $relation->getLocal(), - 'table' => $relation->getAssociationTable()->getTableName(), - 'foreign' => $this->getIdentifier(), - 'foreignTable' => $this->getTableName()); - - - if (($key = array_search($def, $options['foreignKeys'])) === false) { - $options['foreignKeys'][] = $def; - - $constraints[] = $integrity; - } else { - if ($integrity !== $emptyIntegrity) { - $constraints[$key] = $integrity; - } - } - - $def = array('local' => $relation->getForeign(), - 'table' => $relation->getAssociationTable()->getTableName(), 'foreign' => $this->getIdentifier(), 'foreignTable' => $relation->getTable()->getTableName()); if (($key = array_search($def, $options['foreignKeys'])) === false) { $options['foreignKeys'][] = $def; - if ( ! isset($integrity['onDelete'])) { - $integrity['onDelete'] = 'CASCADE'; - } - $constraints[] = $integrity; } else { if ($integrity !== $emptyIntegrity) { - if ( ! isset($integrity['onDelete'])) { - $integrity['onDelete'] = 'CASCADE'; - } - $constraints[$key] = $integrity; } } - */ - } elseif ($relation instanceof Doctrine_Relation_Association) { - /** - $def = array('local' => $relation->getLocal(), - 'table' => $relation->getAssociationTable()->getTableName(), - 'foreign' => $this->getIdentifier(), - 'foreignTable' => $this->getTableName()); - if (($key = array_search($def, $options['foreignKeys'])) === false) { - $options['foreignKeys'][] = $def; - - if ( ! isset($integrity['onDelete'])) { - $integrity['onDelete'] = 'CASCADE'; - } - - $constraints[] = $integrity; - } else { - if ($integrity !== $emptyIntegrity) { - if ( ! isset($integrity['onDelete'])) { - $integrity['onDelete'] = 'CASCADE'; - } - $constraints[$key] = $integrity; - } - } - */ } - } foreach ($constraints as $k => $def) { diff --git a/tests/Export/RecordTestCase.php b/tests/Export/RecordTestCase.php index d93c1ee5b..583b71cb9 100644 --- a/tests/Export/RecordTestCase.php +++ b/tests/Export/RecordTestCase.php @@ -45,6 +45,14 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase $this->init = true; } + public function testExportSupportsForeignKeys() + { + $sql = $this->conn->export->exportClassesSql(array('ForeignKeyTest')); + + $this->assertEqual($sql[0], 'CREATE TABLE foreign_key_test (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, parent_id BIGINT, INDEX parent_id_idx (parent_id), PRIMARY KEY(id)) ENGINE = INNODB'); + $this->assertEqual($sql[1], 'ALTER TABLE foreign_key_test ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES foreign_key_test(id) ON UPDATE RESTRICT ON DELETE CASCADE'); + } + public function testExportSupportsIndexes() { $sql = $this->conn->export->exportClassesSql(array('MysqlIndexTestRecord')); @@ -59,15 +67,6 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase $this->assertEqual($sql[0], 'CREATE TABLE mysql_test_record (name TEXT, code BIGINT, PRIMARY KEY(name, code)) ENGINE = INNODB'); } - - public function testExportSupportsForeignKeys() - { - $sql = $this->conn->export->exportClassesSql(array('ForeignKeyTest')); - - $this->assertEqual($sql[0], 'CREATE TABLE foreign_key_test (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, parent_id BIGINT, INDEX parent_id_idx (parent_id), PRIMARY KEY(id)) ENGINE = INNODB'); - $this->assertEqual($sql[1], 'ALTER TABLE foreign_key_test ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES foreign_key_test(id) ON UPDATE RESTRICT ON DELETE CASCADE'); - } - public function testExportSupportsForeignKeysWithoutAttributes() { $sql = $this->conn->export->exportClassesSql(array('ForeignKeyTest')); @@ -86,6 +85,7 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase $this->assertEqual($sql[0], 'CREATE TABLE mysql_group (id BIGINT AUTO_INCREMENT, name TEXT, PRIMARY KEY(id)) ENGINE = INNODB'); } + public function testExportModelFromDirectory() { Doctrine::export(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files2'); @@ -96,6 +96,7 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION'); } + } class ForeignKeyTest extends Doctrine_Record { diff --git a/tests/run.php b/tests/run.php index c12b9e4a9..54601bcfe 100644 --- a/tests/run.php +++ b/tests/run.php @@ -72,7 +72,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); $test->addTestCase(new Doctrine_Ticket330_TestCase()); */ -/** */ +/** */ // Connection drivers (not yet fully tested) $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase()); @@ -124,6 +124,7 @@ $test->addTestCase(new Doctrine_Export_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Export_Oracle_TestCase()); $test->addTestCase(new Doctrine_Export_Record_TestCase()); $test->addTestCase(new Doctrine_Export_Mysql_TestCase()); + $test->addTestCase(new Doctrine_Export_Sqlite_TestCase()); //$test->addTestCase(new Doctrine_CascadingDelete_TestCase()); @@ -301,7 +302,7 @@ $test->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); $test->addTestCase(new Doctrine_Query_TestCase()); -$test->addTestCase(new Doctrine_Ticket364_TestCase()); +$test->addTestCase(new Doctrine_Ticket364_TestCase()); /** */ //$test->addTestCase(new Doctrine_IntegrityAction_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase());