php - hasAndBelongsToMany in CakePHP 2.x -


i need simple relationchip in cakephp 2.x, believe right not working:

customer.php (model)

public $hasandbelongstomany = array(     'note' => array(         'classname' => 'note',         'jointable' => 'customers_notes',         'foreignkey' => 'customer_id',         'associationforeignkey' => 'note_id',         'unique' =>false,         'dependent'=>true,     ) ); 

note.php (model)

public $hasandbelongstomany = array(     'customer' => array(         'classname' => 'customer',         'jointable' => 'customers_notes',         'foreignkey' => 'note_id',         'associationforeignkey' => 'customer_id',         'unique' =>false,         'dependent'=>true     ) ); 

custumerscontroller.php (controller make find)

public function admin_notes($id=null){     $this->layout="adm.admin";      $all = $this->customer->note->find('all', array(         'limit' => 10,         'conditions' => array(             "customersnote.customer_id" => $id         ),         'order'=>'customersnote.id desc'     ));     $this->set('notes', $all); } 

the error

sql query: select `note`.`id`, `note`.`titulo`, `note`.`conteudo`, `note`.`created`, `note`.`modified`, `note`.`user_id` `crm_prado`.`notes` `note` `customersnote`.`customer_id` = '1' limit 10 

thanks!

the soluction simple.

in find uses

$all = $this->customer->find('all', array(         'recursive'=>2,         'conditions'=>array(             'customer.id'=>$id         )  )); 

works!, recursive mode don't work...


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -