2013-05-30 37 views
1

我有一个模型:翻译行为(查询超时)

class Product extends AppModel {  
    var $actsAs=array(  
     'Translate' => array(
     'title', 'excerpt', 'overview', 'construction', 'options', 'features', 'benefits' 
     ) 
    );  
} 

在我的控制,我查询:

$this->Product->findPublic('all'); 

似乎默认行为是增加一个别名为每个翻译例如:

SELECT `Product`.*, `I18n__title`.`content`, `I18n__excerpt`.`content`, `I18n__overview`.`content`, `I18n__construction`.`content`, `I18n__options`.`content`, `I18n__features`.`content`, `I18n__benefits`.`content` FROM `ck_products` AS `Product` LEFT JOIN `ck_i18n` AS `I18n__title` ON (`Product`.`id` = `I18n__title`.`foreign_key` AND `I18n__title`.`model` = 'Product' AND `I18n__title`.`field` = 'title') LEFT JOIN `ck_i18n` AS `I18n__excerpt` ON (`Product`.`id` = `I18n__excerpt`.`foreign_key` AND `I18n__excerpt`.`model` = 'Product' AND `I18n__excerpt`.`field` = 'excerpt') LEFT JOIN `ck_i18n` AS `I18n__overview` ON (`Product`.`id` = `I18n__overview`.`foreign_key` AND `I18n__overview`.`model` = 'Product' AND `I18n__overview`.`field` = 'overview') LEFT JOIN `ck_i18n` AS `I18n__construction` ON (`Product`.`id` = `I18n__construction`.`foreign_key` AND `I18n__construction`.`model` = 'Product' AND `I18n__construction`.`field` = 'construction') LEFT JOIN `ck_i18n` AS `I18n__options` ON (`Product`.`id` = `I18n__options`.`foreign_key` AND `I18n__options`.`model` = 'Product' AND `I18n__options`.`field` = 'options') LEFT JOIN `ck_i18n` AS `I18n__features` ON (`Product`.`id` = `I18n__features`.`foreign_key` AND `I18n__features`.`model` = 'Product' AND `I18n__features`.`field` = 'features') LEFT JOIN `ck_i18n` AS `I18n__benefits` ON (`Product`.`id` = `I18n__benefits`.`foreign_key` AND `I18n__benefits`.`model` = 'Product' AND `I18n__benefits`.`field` = 'benefits') WHERE `Product`.`status` = 'active' AND NOT (`Product`.`slug` = '') AND `I18n__title`.`locale` = 'eng' AND `I18n__excerpt`.`locale` = 'eng' AND `I18n__overview`.`locale` = 'eng' AND `I18n__construction`.`locale` = 'eng' AND `I18n__options`.`locale` = 'eng' AND `I18n__features`.`locale` = 'eng' AND `I18n__benefits`.`locale` = 'eng' 

我添加的字段越多,查询得到的越慢。事实上,它现在超时了。 有没有更好的方法在Cake中做到这一点?

+1

这是我从不使用这种行为的主要原因,海事组织只是太低效。作为替代,我们开发了一个内部解决方案,为每个可翻译的模型/表格使用翻译表。基本上,一个“阴影”表,包含每个记录的翻译。没有翻译的记录可以省略,也可以回到默认/主要语言。可以使用语言环境列来指定语言,将翻译存储在单独的表中或同一个表中。 – thaJeztah

+0

刚刚和一位同事聊过这个问题,他提出的建议几乎和@ thaJeztah完全一样,所以在我的第一次搜索中找到它就很有趣。这似乎是一个很好的方法,因为Cake的翻译行为是一个真正的使用痛苦。 – drmonkeyninja

回答

1

伊夫使用行为只返回一些解决了我的问题的领域之一:

$this->Product->Behaviors->attach('Translate', array('title')); 

我仍然在答案被insterested如果你有,比如说,20场翻译,并要求他们在所有上市一个观点。