diff --git a/generator/lib/behavior/i18n/I18nBehavior.php b/generator/lib/behavior/i18n/I18nBehavior.php index 21adb0a6d..2b029cc11 100644 --- a/generator/lib/behavior/i18n/I18nBehavior.php +++ b/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())) { diff --git a/generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php b/generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php index 0b3d3a7f8..76407bb6f 100644 --- a/generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php +++ b/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(), )); } diff --git a/generator/lib/behavior/i18n/templates/objectGetTranslation.php b/generator/lib/behavior/i18n/templates/objectGetTranslation.php index f26d116a8..5ec372564 100644 --- a/generator/lib/behavior/i18n/templates/objectGetTranslation.php +++ b/generator/lib/behavior/i18n/templates/objectGetTranslation.php @@ -23,8 +23,10 @@ public function getTranslation($locale = '', PropelP $translation = new (); $translation->set($locale); } else { + $pk = is_array($this->getPrimaryKey()) ? $this->getPrimaryKey() : array($this->getPrimaryKey()); + $pk[] = $locale; $translation = ::create() - ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->filterByPrimaryKey($pk) ->findOneOrCreate($con); $this->currentTranslations[$locale] = $translation; } diff --git a/generator/lib/behavior/i18n/templates/objectRemoveTranslation.php b/generator/lib/behavior/i18n/templates/objectRemoveTranslation.php index 455b8d41e..e31e55a87 100644 --- a/generator/lib/behavior/i18n/templates/objectRemoveTranslation.php +++ b/generator/lib/behavior/i18n/templates/objectRemoveTranslation.php @@ -10,8 +10,10 @@ public function removeTranslation($locale = '', PropelPDO $con = null) { if (!$this->isNew()) { + $pk = is_array($this->getPrimaryKey()) ? $this->getPrimaryKey() : array($this->getPrimaryKey()); + $pk[] = $locale; ::create() - ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->filterByPrimaryKey($pk) ->delete($con); } if (isset($this->currentTranslations[$locale])) {