我有一個翻譯行爲附帶兩個字段的模型:標題和說明。 我在可翻譯字段中添加了一些條件。 像往常一樣分頁,CakePHP首先進行計數,然後提取所有記錄。 當獲取查詢的總記錄: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_ 標題或國際化 _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);
你可以發佈你的控制器代碼嗎? –
我添加了條件的部分。 – mentalic