Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add namespace to check for duplicate table phpName #207

Merged
merged 1 commit into from

2 participants

@havvg

The same phpName for a table should be valid if the models are in different namespaces.

@willdurand
Owner

Thanks for that! I would like to write this patch last week… Would you mind porting this patch on Propel2 ?

@willdurand willdurand merged commit 09cbfbc into from
@havvg havvg deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 30, 2011
  1. @havvg
This page is out of date. Refresh to see the latest.
View
13 generator/lib/util/PropelSchemaValidator.php
@@ -47,11 +47,20 @@ public function validate()
protected function validateDatabaseTables(Database $database)
{
$phpNames = array();
+ $namespaces = array();
foreach ($database->getTables() as $table) {
- if (in_array($table->getPhpName(), $phpNames)) {
+ $list = &$phpNames;
+ if ($table->getNamespace()) {
+ if (!isset($namespaces[$table->getNamespace()])) {
+ $namespaces[$table->getNamespace()] = array();
+ }
+
+ $list = &$namespaces[$table->getNamespace()];
+ }
+ if (in_array($table->getPhpName(), $list)) {
$this->errors[] = sprintf('Table "%s" declares a phpName already used in another table', $table->getName());
}
- $phpNames[]= $table->getPhpName();
+ $list[]= $table->getPhpName();
$this->validateTableAttributes($table);
$this->validateTableColumns($table);
}
View
24 test/testsuite/generator/util/PropelSchemaValidatorTest.php
@@ -68,6 +68,30 @@ public function testValidateReturnsFalseWhenTwoTablesHaveSamePhpName()
$this->assertContains('Table "bar" declares a phpName already used in another table', $validator->getErrors());
}
+ public function testValidateReturnsTrueWhenTwoTablesHaveSamePhpNameInDifferentNamespaces()
+ {
+ $column1 = new Column('id');
+ $column1->setPrimaryKey(true);
+ $table1 = new Table('foo');
+ $table1->addColumn($column1);
+ $table1->setNamespace('Foo');
+
+ $column2 = new Column('id');
+ $column2->setPrimaryKey(true);
+ $table2 = new Table('bar');
+ $table2->addColumn($column2);
+ $table2->setPhpName('Foo');
+ $table2->setNamespace('Bar');
+
+ $database = new Database();
+ $database->addTable($table1);
+ $database->addTable($table2);
+ $appData = new AppData();
+ $appData->addDatabase($database);
+ $validator = new PropelSchemaValidator($appData);
+ $this->assertTrue($validator->validate());
+ }
+
public function testValidateReturnsFalseWhenTableHasNoPk()
{
$appData = $this->getAppDataForTable(new Table('foo'));
Something went wrong with that request. Please try again.