Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add composite primary key support to filterByPrimaryKey in i18nBehavior

  • Loading branch information...
commit 7538f8a0e2a161ea1631a189e6ebf6d21149538f 1 parent e66636c
@kevpie authored
View
3  generator/lib/behavior/i18n/I18nBehavior.php
@@ -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())) {
View
2  generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php
@@ -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(),
));
}
View
9 generator/lib/behavior/i18n/templates/objectGetTranslation.php
@@ -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);
View
9 generator/lib/behavior/i18n/templates/objectRemoveTranslation.php
@@ -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]);
Please sign in to comment.
Something went wrong with that request. Please try again.