Commit 625b6a3f authored by zYne's avatar zYne

--no commit message

--no commit message
parent 741cc3f0
......@@ -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 {
......
......@@ -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
......
......@@ -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) {
......
......@@ -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
{
......
......@@ -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());
......
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