Permalink
Browse files

Added the "locale = $locale" condition to the ON part of the query.

Added "locale = $locale" to the ON part and changed the join type to an INNER join.
Because adding it to the WHERE part caused the translation to be mandatory anyway.
This cleans up the code and "INNER" joins are generally faster than LEFT joins.
  • Loading branch information...
1 parent 96a8d97 commit 9f7126898b5f198bd3999cb00432e37d9037d559 @bfanger bfanger committed Sep 12, 2011
Showing with 3 additions and 11 deletions.
  1. +3 −11 cake/libs/model/behaviors/translate.php
@@ -182,27 +182,19 @@ function beforeFind(&$model, $query) {
} else {
$query['fields'][] = 'I18n__'.$field.'.content';
$query['joins'][] = array(
- 'type' => 'LEFT',
+ 'type' => 'INNER',
'alias' => 'I18n__'.$field,
'table' => $db->name($tablePrefix . $RuntimeModel->useTable),
'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 => $field,
+ 'I18n__'.$field.'.locale' => $locale
)
);
-
- if (is_string($query['conditions'])) {
- $query['conditions'] = $db->conditions($query['conditions'], true, false, $model) . ' AND '.$db->name('I18n__'.$field.'.locale').' = \''.$locale.'\'';
- } else {
- $query['conditions'][$db->name("I18n__{$field}.locale")] = $locale;
- }
}
}
}
- if (is_array($query['fields'])) {
- $query['fields'] = array_merge($query['fields']);
- }
$this->runtime[$model->alias]['beforeFind'] = $addFields;
return $query;
}

0 comments on commit 9f71268

Please sign in to comment.