Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix i18n behavior with table prefix. Fixes #423
  • Loading branch information
willdurand committed Aug 6, 2012
1 parent ddf5b70 commit f9e3c77
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion generator/lib/behavior/i18n/I18nBehavior.php
Expand Up @@ -248,7 +248,7 @@ public function replaceTokens($string)
$table = $this->getTable();

return strtr($string, array(
'%TABLE%' => $table->getName(),
'%TABLE%' => $table->getNonPrefixedName(),
'%PHPNAME%' => $table->getPhpName(),
));
}
Expand Down
12 changes: 10 additions & 2 deletions generator/lib/model/Table.php
Expand Up @@ -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;
Expand Down Expand Up @@ -1976,4 +1976,12 @@ public function hasCrossForeignKeys()
{
return (count($this->getCrossFks()) !== 0);
}

/**
* @return string
*/
public function getNonPrefixedName()
{
return $this->nonPrefixedName;
}
}
24 changes: 24 additions & 0 deletions test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php
Expand Up @@ -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.