【发布时间】:2011-12-07 11:51:18
【问题描述】:
我有一个模型,它具有附加两个字段的翻译行为:标题和描述。 我在可翻译字段中添加了一些条件。 与分页一样,CakePHP 首先进行计数,然后获取所有记录。 获取查询的总记录时:
SELECT COUNT(DISTINCT( `product`.`id` )) AS COUNT
FROM `products` AS `product`
INNER JOIN `i18n` AS `i18nmodel`
ON ( `product`.`id` = `i18nmodel`.`foreign_key`
AND `i18nmodel`.`model` = 'Product'
AND `i18nmodel`.`locale` = 'eng' )
LEFT JOIN `categories` AS `category`
ON ( `product`.`category_id` = `category`.`id` )
LEFT JOIN `vats` AS `vat`
ON ( `product`.`vat_id` = `vat`.`id` )
LEFT JOIN `availables` AS `available`
ON ( `product`.`available_id` = `available`.`id` )
WHERE ( ( `i18n__description`.`content` LIKE '%test%' )
OR ( `i18n__title`.`content` LIKE '%test%' )
OR ( `product`.`code` LIKE '%test%' ) )
我明白了:
1054: Unknown column 'I18n__description.content' in 'where clause'
因为 i18n 表不是作为 i18n_title 或 i18n_description 而是作为 i18nmodel 加入的
但是,当分页尝试检索查询的行(而不是总记录)时,一切正常。有什么解决办法吗?
控制器代码如下所示:
$condition = array();
foreach ($search as $word) {
if (strlen($word) > 0)
$condition[] = array('OR' => array('I18n__description.content LIKE' => '%' . $word . '%','I18n__title.content LIKE' => '%' . $word . '%',
'Product.code LIKE' => '%' . $word . '%'));
}
$conditions = array('AND' => $condition);
$products = $this->paginate($conditions);
【问题讨论】:
-
你能发布你的控制器代码吗?
-
我添加了条件部分。
标签: cakephp internationalization pagination