Skip to content

Commit

Permalink
Fix the 'Table "t1" declared twice' when same table name are declared…
Browse files Browse the repository at this point in the history
… on different schema fix #311
  • Loading branch information
Raphaël Davaillaud committed Aug 28, 2012
1 parent 19dc671 commit 725518f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion generator/lib/model/Database.php
Expand Up @@ -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());
}
Expand Down
17 changes: 16 additions & 1 deletion test/testsuite/generator/model/DatabaseTest.php
@@ -1,4 +1,4 @@
<?php
<?php

/*
* $Id: TableTest.php 1965 2010-09-21 17:44:12Z francois $
Expand Down Expand Up @@ -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.