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

Already on GitHub? Sign in to your account

i18nBehavior Composite Primary Key Support #479

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+18 −5
Split
@@ -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())) {
@@ -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(),
));
}
@@ -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(),
));
}
@@ -1,4 +1,3 @@
-
/**
* Returns the current translation for a given locale
*
@@ -23,9 +22,17 @@ public function getTranslation($locale = '<?php echo $defaultLocale ?>', PropelP
$translation = new <?php echo $i18nTablePhpName ?>();
$translation->set<?php echo $localeColumnName ?>($locale);
} else {
+<?php if ($isCompositePrimaryKey): ?>
+ $pk = $this->getPrimaryKey();
+ $pk[] = $locale;
+ $translation = <?php echo $i18nQueryName ?>::create()
+ ->filterByPrimaryKey($pk)
+ ->findOneOrCreate($con);
+<?php else: ?>
$translation = <?php echo $i18nQueryName ?>::create()
->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
->findOneOrCreate($con);
+<?php endif; ?>
$this->currentTranslations[$locale] = $translation;
}
$this->add<?php echo $i18nSetterMethod ?>($translation);
@@ -1,4 +1,3 @@
-
/**
* Remove the translation for a given locale
*
@@ -10,9 +9,17 @@
public function removeTranslation($locale = '<?php echo $defaultLocale ?>', PropelPDO $con = null)
{
if (!$this->isNew()) {
+<?php if ($isCompositePrimaryKey): ?>
+ $pk = $this->getPrimaryKey();
+ $pk[] = $locale;
+ <?php echo $i18nQueryName ?>::create()
+ ->filterByPrimaryKey($pk)
+ ->delete($con);
+<?php else: ?>
<?php echo $i18nQueryName ?>::create()
->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
->delete($con);
+<?php endif; ?>
}
if (isset($this->currentTranslations[$locale])) {
unset($this->currentTranslations[$locale]);