0
I have a relationship between 2 models
: Ramais
and Setores
, and print the data of the 2 on the screen, but I need to run a Search field, but I was only able to search the data of the table Ramais
, as name and extension, the data of Setores
I can’t pull from the bench, someone has some hint of what I’m 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');
}
}
He brings the following error:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Setores.name' in 'where clause'
you set up the class
Ramais
with the relationship ?– novic
Good afternoon, yes I related that way. $this->belongsToMany('Sectors', [ 'foreignKey' => 'ramai_id', 'targetForeignKey' => 'setore_id', 'joinTable' => 'ramais_sectors' ]);
– Rodrigo Gaster
The column
name
exists even in the tableSetores
?– Guilherme Nascimento