Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing composite keyed tables to use i18n behavior #1092

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions generator/lib/behavior/i18n/I18nBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ protected function relateI18nTableToMainTable()
$table = $this->getTable();
$i18nTable = $this->i18nTable;
$pks = $this->getTable()->getPrimaryKey();
if (count($pks) > 1) {
throw new EngineException('The i18n behavior does not support tables with composite primary keys');
}
$i18nPkName = $this->getParameter('i18n_pk_name');
foreach ($pks as $column) {
if (!$i18nTable->hasColumn($column->getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function addGetTranslation()
'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
'i18nQueryName' => $this->builder->getNewStubQueryBuilder($i18nTable)->getClassname(),
'i18nSetterMethod' => $this->builder->getRefFKPhpNameAffix($fk, $plural = false),
'isCompositePrimaryKey' => $this->behavior->getTable()->hasCompositePrimaryKey(),
));
}

Expand All @@ -130,6 +131,7 @@ protected function addRemoveTranslation()
'i18nQueryName' => $this->builder->getNewStubQueryBuilder($i18nTable)->getClassname(),
'i18nCollection' => $this->builder->getRefFKCollVarName($fk),
'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
'isCompositePrimaryKey' => $this->behavior->getTable()->hasCompositePrimaryKey(),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public function getTranslation($locale = '<?php echo $defaultLocale ?>', PropelP
$translation = new <?php echo $i18nTablePhpName ?>();
$translation->set<?php echo $localeColumnName ?>($locale);
} else {
$pk = is_array($this->getPrimaryKey()) ? $this->getPrimaryKey() : array($this->getPrimaryKey());
$pk[] = $locale;
$translation = <?php echo $i18nQueryName ?>::create()
->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
->filterByPrimaryKey($pk)
->findOneOrCreate($con);
$this->currentTranslations[$locale] = $translation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
public function removeTranslation($locale = '<?php echo $defaultLocale ?>', PropelPDO $con = null)
{
if (!$this->isNew()) {
$pk = is_array($this->getPrimaryKey()) ? $this->getPrimaryKey() : array($this->getPrimaryKey());
$pk[] = $locale;
<?php echo $i18nQueryName ?>::create()
->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
->filterByPrimaryKey($pk)
->delete($con);
}
if (isset($this->currentTranslations[$locale])) {
Expand Down