Skip to content
Browse files

Fix the 'Table "t1" declared twice' when same table name are declared…

… on different schema fix #311
  • Loading branch information...
1 parent 19dc671 commit 725518feafaec5ee5454f03605398107c50260e4 @rdavaillaud rdavaillaud committed
Showing with 17 additions and 2 deletions.
  1. +1 −1 generator/lib/model/Database.php
  2. +16 −1 test/testsuite/generator/model/DatabaseTest.php
View
2 generator/lib/model/Database.php
@@ -379,10 +379,10 @@ public function addTable($data)
{
if ($data instanceof Table) {
$tbl = $data; // alias
+ $tbl->setDatabase($this);
if (isset($this->tablesByName[$tbl->getName()])) {
throw new EngineException(sprintf('Table "%s" declared twice', $tbl->getName()));
}
- $tbl->setDatabase($this);
if ($tbl->getSchema() === null) {
$tbl->setSchema($this->getSchema());
}
View
17 test/testsuite/generator/model/DatabaseTest.php
@@ -1,4 +1,4 @@
-<?php
+ <?php
/*
* $Id: TableTest.php 1965 2010-09-21 17:44:12Z francois $
@@ -128,4 +128,19 @@ public function testAddTableSkipsDatabaseNamespaceWhenTableNamespaceIsAbsolute()
$this->assertEquals('Bar', $t1->getNamespace());
}
+ public function testAddTableWithSameNameOnDifferentSchema()
+ {
+ $db = new Database();
+ $db->setPlatform(new SchemaPlatform());
+
+ $t1 = new Table('t1');
+ $db->addTable($t1);
+ $this->assertEquals('t1', $t1->getName());
+
+ $t1b = new Table('t1');
+ $t1b->setSchema('bis');
+ $db->addTable($t1b);
+ $this->assertEquals('bis.t1', $t1b->getName());
+ }
+
}

0 comments on commit 725518f

Please sign in to comment.
Something went wrong with that request. Please try again.