1
votes

in the search function i have this piece of code

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,
            );
        }

and when i execute the query i have this error

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

this is the table

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 ;

this is the ClientCode model

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

and these are the relations of the ProductComponent model

<?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');

I don't understand why...PLEASE HELP. Thanks!

1
do you have ClientCode.client_component_code column in your database?Marek Sebera
only the last condition doesn't work, the others work finemirko.cek
yes Marek i have that column in my databasemirko.cek
than clear your cache in /app/tmp (and all subfolders) and try again, otherwise, it's problem of your model definition/implementationMarek Sebera
post both, model class and database table creating SQL sequence, and append it to your question, via link edit under itMarek Sebera

1 Answers

1
votes

Are you using containable? It sounds like you are trying to perform a condition on a non-joined table.