cakephp data from multiple tables join query -


i working on cakephp 2.x. have query this:

  $this->bindmodel(array(         'belongsto' => array(             'contact' => array(                 'classname' => 'contact',                 'foreignkey' => false,                 'conditions' => array(                     'message.user_id = contact.user_id',                             array('message.mobileno' => array('contact.mobileno',                            'contact.workno',                             'contact.homeno',                              'contact.other')),                 ),                 'order'=>'message.idtextmessage desc',             )         )     ), false);      return $this->find('all', array('conditions' => array('message.user_id' => $userid),         'contain' => array('contact' ),         'fields' => array('message.mobileno',             'contact.mobileno',             'contact.workno',             'contact.homeno',             'contact.other',             'contact.name',             'message.datetime',             'message.type',             'message.body'),         'group' => 'message.mobileno',         'limit' => 6)); } 

the query not working expected. figure out problem .the problem when print query.it adding single quotation (' ') around ('contact.mobileno') , message.mobileno in ('contact.mobileno', 'contact.workno', 'contact.homeno', 'contact.other'))

so when remove quotations in sql yog. query works. mean think not finding mobileno,workno, etc contacts here in part. 1 know should do?

well if want see simple sql query working perfect.. here

          select message.mobileno,         contact.mobileno,         contact.workno,         contact.homeno,         contact.other,         contact.name,          message.body,         message.idtextmessage    cakephp_db.textmessage message    left join cakephp_db.contacts contact on message.user_id = contact.user_id                                      , message.mobileno in (contact.mobileno,           contact.workno, contact.homeno, contact.other)  message.user_id = 23  group message.mobileno order message.idtextmessage desc limit 6 

you should change to:

$this->bindmodel(array(         'belongsto' => array(             'contact' => array(                 'classname' => 'contact',                 'foreignkey' => false,                 'conditions' => array(                     'message.user_id = contact.user_id',                     '`message`.`mobileno` in (`contact`.`mobileno`,`contact`.`workno`,`contact`.`homeno`,`contact`.`other`)'),                 'order'=>'message.idtextmessage desc',             )         )     ), false); 

when use key-value conditions , cake consider value string value not column name.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -