CakePHP i18n,在使用带条件的find()时转换行为,未知列错误

时间:2009-11-03 06:50:35

标签: cakephp internationalization translation

我正在尝试使翻译行为正常工作,我从原始表中删除了已翻译的comlumns,现在我在执行以下查询时遇到错误:

$menu = $this->Menu->find('first', array('conditions' => array('Menu.title' => 'main-nav')));

我的菜单型号:

<?php
class Menu extends AppModel {
    var $name = 'Menu';

    var $actsAs = array(
        'Translate' => array(
            'title', 'link_title', 'path'
        ),
        'Tree'
    );

    /*var $belongsTo = array('Content'); disabled for now.. */
}
?>

这是生成的SQL /错误:

Warning (512): SQL Error: 1054: Unknown column 'Menu.title' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 525]

Query: SELECT `Menu`.*, `I18n__title`.`content`, `I18n__link_title`.`content`, `I18n__path`.`content` FROM `ags_menus` AS `Menu` LEFT JOIN `ags_i18n` AS `I18n__title` ON (`Menu`.`id` = `I18n__title`.`foreign_key` AND `I18n__title`.`model` = 'Menu' AND `I18n__title`.`field` = 'title') LEFT JOIN `ags_i18n` AS `I18n__link_title` ON (`Menu`.`id` = `I18n__link_title`.`foreign_key` AND `I18n__link_title`.`model` = 'Menu' AND `I18n__link_title`.`field` = 'link_title') LEFT JOIN `ags_i18n` AS `I18n__path` ON (`Menu`.`id` = `I18n__path`.`foreign_key` AND `I18n__path`.`model` = 'Menu' AND `I18n__path`.`field` = 'path') WHERE `Menu`.`title` = 'main-nav' AND `I18n__title`.`locale` = 'en_gb' AND `I18n__link_title`.`locale` = 'en_gb' AND `I18n__path`.`locale` = 'en_gb' LIMIT 1 

显然我得到了错误,因为菜单模型/表中的列不再存在,但我认为翻译行为会自动处理这个问题吗?

1 个答案:

答案 0 :(得分:4)

我设法找到了解决方案:

'conditions' => array('I18n__title.content' => 'main-nav')