cakePHP搜索功能

时间:2012-01-19 23:56:51

标签: cakephp cakephp-1.3

在搜索功能中我有这段代码

foreach($words as $word) {

            $search = '%'.$word.'%';

            $query['conditions'][]['or'] = array(
                'ProductComponent.codice LIKE' => $search,
                'ProductComponent.nome'.__('_it', true).' LIKE' => $search,
                'ComponentType.nome'.__('_it', true).' LIKE' => $search,
                'Material.nome'.__('_it', true).' LIKE' => $search,
                'Finish.nome'.__('_it', true).' LIKE' => $search,
                'ClientCode.client_component_code LIKE' => $search,
            );
        }

当我执行查询时出现此错误

  

警告(512):SQL错误:1054:未知列   'where子句'中的'ClientCode.client_component_code'   [CORE / cake / libs / model / datasources / dbo_source.php,第684行]

这是表格

CREATE TABLE IF NOT EXISTS `client_codes` (
`id` int(10) NOT NULL auto_increment,
`user_id` int(10) NOT NULL,
`product_component_id` int(10) NOT NULL,
`client_component_code` varchar(255) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=225 ;

这是ClientCode模型

<?php
class ClientCode extends AppModel {
var $name = 'ClientCode';
var $belongsTo = array('ProductComponent', 'User');
}
?>

这些是ProductComponent模型的关系

<?php
class ProductComponent extends AppModel {
var $name = 'ProductComponent';
var $belongsTo = array('ComponentType', 'Material', 'Finish','Line');
var $hasMany = array(
    'Part', 
    'RelatedComponent',
    'LineRelatedComponent' => array(
        'className'  => 'RelatedComponent',
        'conditions' => array('NOT' => array('LineRelatedComponent.line_id' => NULL)),
    ),
    'GenericRelatedComponent' => array(
        'className'  => 'RelatedComponent',
        'conditions' => array('GenericRelatedComponent.line_id' => NULL),
    ),
    'CustomPriceList',
    'PriceList',
    'ClientCode'
);
var $hasAndBelongsToMany = array('Upload');

我不明白为什么......请帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

您使用的是可容纳的吗?听起来你正试图在非连接表上执行条件。