From ce490b1df2e0095aa2c20b89c765b3800a9d91d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 26 Oct 2010 18:22:13 -0430 Subject: [PATCH] Fixing issues with translatable field aliasing in TranslateBehavior --- cake/libs/model/behaviors/translate.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index 44336462a..8f9256dfa 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -131,8 +131,10 @@ class TranslateBehavior extends ModelBehavior { $this->runtime[$model->alias]['virtualFields'] = $model->virtualFields; if ($addFields) { - foreach ($addFields as $field) { - foreach (array($field, $model->alias.'.'.$field) as $_field) { + foreach ($addFields as $_f => $field) { + $aliasField = is_numeric($_f) ? $field : $_f; + + foreach (array($aliasField, $model->alias.'.'.$aliasField) as $_field) { $key = array_search($_field, (array)$query['fields']); if ($key !== false) { @@ -153,7 +155,7 @@ class TranslateBehavior extends ModelBehavior { 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"), 'I18n__'.$field.'__'.$_locale.'.model' => $model->name, - 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $field, + 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $aliasField, 'I18n__'.$field.'__'.$_locale.'.locale' => $_locale ) ); @@ -170,7 +172,7 @@ class TranslateBehavior extends ModelBehavior { 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"), 'I18n__'.$field.'.model' => $model->name, - 'I18n__'.$field.'.'.$RuntimeModel->displayField => $field + 'I18n__'.$field.'.'.$RuntimeModel->displayField => $aliasField ) );