Skip to content

Commit

Permalink
Merge pull request #302 from K-Phoen/fix-issue-301
Browse files Browse the repository at this point in the history
Fix: issue #301
  • Loading branch information
willdurand committed Aug 31, 2012
2 parents c8dcbc9 + 8b84a20 commit 4656d45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Propel/Generator/Model/Database.php
Expand Up @@ -416,11 +416,12 @@ public function addTable($table)
return $this->addTable($tbl); return $this->addTable($tbl);
} }


$table->setDatabase($this);

if (isset($this->tablesByName[$table->getName()])) { if (isset($this->tablesByName[$table->getName()])) {
throw new EngineException(sprintf('Table "%s" declared twice', $table->getName())); throw new EngineException(sprintf('Table "%s" declared twice', $table->getName()));
} }


$table->setDatabase($this);
if (null === $table->getSchema()) { if (null === $table->getSchema()) {
$table->setSchema($this->getSchema()); $table->setSchema($this->getSchema());
} }
Expand Down
17 changes: 17 additions & 0 deletions tests/Propel/Tests/Generator/Model/DatabaseTest.php
Expand Up @@ -11,6 +11,8 @@
namespace Propel\Tests\Generator\Model; namespace Propel\Tests\Generator\Model;


use Propel\Generator\Model\Database; use Propel\Generator\Model\Database;
use Propel\Generator\Model\Table;
use Propel\Generator\Platform\PgsqlPlatform;


/** /**
* Unit test suite for Database model class. * Unit test suite for Database model class.
Expand Down Expand Up @@ -418,4 +420,19 @@ public function testSetDefaultPhpNamingMethodStrategy()


$this->assertSame('foo', $database->getDefaultPhpNamingMethod()); $this->assertSame('foo', $database->getDefaultPhpNamingMethod());
} }

public function testAddTableWithSameNameOnDifferentSchema()
{
$db = new Database();
$db->setPlatform(new PgsqlPlatform());

$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 4656d45

Please sign in to comment.