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.
This commit is contained in:
Bob Fanger 2011-09-12 12:22:59 +02:00
parent 96a8d97de7
commit 9f7126898b

View file

@ -182,27 +182,19 @@ class TranslateBehavior extends ModelBehavior {
} else { } else {
$query['fields'][] = 'I18n__'.$field.'.content'; $query['fields'][] = 'I18n__'.$field.'.content';
$query['joins'][] = array( $query['joins'][] = array(
'type' => 'LEFT', 'type' => 'INNER',
'alias' => 'I18n__'.$field, 'alias' => 'I18n__'.$field,
'table' => $db->name($tablePrefix . $RuntimeModel->useTable), 'table' => $db->name($tablePrefix . $RuntimeModel->useTable),
'conditions' => array( 'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"), $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"),
'I18n__'.$field.'.model' => $model->name, '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; $this->runtime[$model->alias]['beforeFind'] = $addFields;
return $query; return $query;
} }