Browse files

Fix i18n behavior with table prefix. Fixes #423

  • Loading branch information...
1 parent ddf5b70 commit f9e3c77e2716ff2836721d5aeb14016549856b17 @willdurand willdurand committed Aug 6, 2012
View
2 generator/lib/behavior/i18n/I18nBehavior.php
@@ -248,7 +248,7 @@ public function replaceTokens($string)
$table = $this->getTable();
return strtr($string, array(
- '%TABLE%' => $table->getName(),
+ '%TABLE%' => $table->getNonPrefixedName(),
'%PHPNAME%' => $table->getPhpName(),
));
}
View
12 generator/lib/model/Table.php
@@ -88,10 +88,10 @@ class Table extends ScopedElement implements IDMethod
* @var string
*/
private $commonName;
-
+
/**
* Table name without prefix. Only used for phpName generation.
- *
+ *
* @var string
*/
private $nonPrefixedName;
@@ -1976,4 +1976,12 @@ public function hasCrossForeignKeys()
{
return (count($this->getCrossFks()) !== 0);
}
+
+ /**
+ * @return string
+ */
+ public function getNonPrefixedName()
+ {
+ return $this->nonPrefixedName;
+ }
}
View
24 test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php
@@ -401,4 +401,28 @@ public function testModifyTableUseCustomPkName()
$this->assertContains($expected, $builder->getSQL());
}
+
+ public function testTableWithPrefix()
+ {
+ $schema = <<<EOF
+<database name="default" tablePrefix="plop_">
+ <table name="group">
+ <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
+ <column name="title" type="varchar" primaryString="true" size="255" />
+
+ <behavior name="i18n">
+ <parameter name="i18n_columns" value="title" />
+ <parameter name="locale_column" value="locale" />
+ </behavior>
+ </table>
+</database>
+EOF;
+
+ $builder = new PropelQuickBuilder();
+ $builder->setSchema($schema);
+
+ $this->assertTrue($builder->getDatabase()->hasTable('plop_group'));
+ $this->assertFalse($builder->getDatabase()->hasTable('plop_plop_group_i18n'));
+ $this->assertTrue($builder->getDatabase()->hasTable('plop_group_i18n'));
+ }
}

0 comments on commit f9e3c77

Please sign in to comment.