I have a relationship between 2 models
: Ramais
and Setores
, and print the data from the 2 on the screen, but I need to make a Search field work, but I was only able to search the table data of Ramais
, like name and extension, data of Setores
I can not pull from the bank, does anyone have any clue what I am doing wrong?
public function search()
{
$ramais = $this->paginate($this->Ramais);
if ($this->request->is('post')) {
$search = null;
if (isset($this->request->data['search'])) {
$search = $this->request->data['search'];
}
$ramal = $this->Ramais->find('all',
[
'contain' => ['Setores'],
'conditions'=>['OR'=>
[
'Ramais.name LIKE'=>'%'.$search.'%',
'Ramais.ramal LIKE'=>'%'.$search.'%',
'Setores.name LIKE'=>'%'.$search.'%'
]
]
]
);
//debug($ramal); exit();
$this->set(compact('ramais', 'ramal', 'setor'));
$this->set('_serialize', ['ramais'], ['setor']);
$this->render('index');
}
}
It brings the following error :
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Setores.name' in 'where clause'