Hi,
I try to migrate a v3.x cake project to v5.x. My categories table has content in different languages in the i18n table (default schema from config/schema/i18n.sql).
When I enable the TranslateBehavior in the CategoriesTable model with the EavStrategy:
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('categories');
$this->setDisplayField('title');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Translate', [
'strategyClass' => Cake\ORM\Behavior\Translate\EavStrategy::class,
'fields' => ['title']
]);
I do not receive the translated content. These are the queries from the two projects:
Works:
SELECT `Category`.`id`, (`I18n__title`.`content`) AS `Category__i18n_title`
FROM `dgp_wegweiser`.`categories` AS `Category`
INNER JOIN `dgp_wegweiser`.`i18n` AS `I18n__title`
ON (`Category`.`id` = `I18n__title`.`foreign_key` AND `I18n__title`.`model` = 'Category' AND
`I18n__title`.`field` = 'title' AND `I18n__title`.`locale` = 'en')
WHERE `Category`.`is_for_children` = '0'
ORDER BY `Category`.`category_order` ASC
Doesn’t work:
SELECT
Categories.id AS Categories__id,
Categories.title AS Categories__title,
Categories_title_translation.id AS Categories_title_translation__id,
Categories_title_translation.content AS Categories_title_translation__content
FROM
categories Categories
LEFT JOIN i18n Categories_title_translation ON (
Categories_title_translation.model = 'Categories'
AND Categories_title_translation.field = 'title'
AND Categories_title_translation.locale = 'en'
AND Categories.id = Categories_title_translation.foreign_key
)
WHERE is_for_children = FALSE
ORDER BY category_order ASC
What am I doing wrong?
Thanks for your help!
Mathias