mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
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:
parent
96a8d97de7
commit
9f7126898b
1 changed files with 3 additions and 11 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue