Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

i18nBehavior Composite Primary Key Support #479

Closed
wants to merge 2 commits into from

4 participants

@kevpie

filterByPrimaryKey needed to be able to be called for a composite primary key which exists as an array versus a string for a regular primary key.

I have no idea what else may be missing in terms of suport for saving.

This seems to work for fetching.

Looking for guidance.

@jaugustin
Collaborator

Good work, could you add tests to prove that it work as expected ?

@willdurand
Owner

Yeah, some unit tests would be nice :)

@kevpie
@willdurand
Owner

@kevpie Hey Kevin, could you push a unit test here?

@willdurand
Owner

Ping @kevpie

@willdurand willdurand closed this
@staabm
Collaborator

What about this change...? Closed because of inactivity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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]);
Something went wrong with that request. Please try again.