I have a Custom Finder Method in the model and trying to call it in the controller it is not found.
follows the code in the model VehiclesTable.php:
public function listarVeiculosDisponiveis(Query $query, array $options)
{
return $query->where(['empresa_id' => 1]);
}
in the file OrcamentosController.php I have the following method:
public function add()
{
$orcamento = $this->Orcamentos->newEntity();
if ($this->request->is('post')) {
$orcamento = $this->Orcamentos->patchEntity($orcamento, $this->request->data);
$orcamento['empresa_id'] = $this->Auth->user('empresa_id');
$orcamento['user_id'] = $this->Auth->user('id');
if ($this->Orcamentos->save($orcamento)) {
$this->Flash->success(__('O orçamento foi salvo com sucesso.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('Erro ao salvar orçamento, tente novamente.'));
}
}
$clientes = $this->Orcamentos->Clientes->find('list', [ 'conditions' => ['empresa_id' => $this->Auth->user('empresa_id'), 'excluido' => 0], 'fields' => ['id', 'nome'] ]);
$veiculos = TableRegistry::get('Veiculos');
$veiculos_disponiveis = $veiculos->find('listarVeiculosDisponiveis');
$users = $this->Orcamentos->Users->find('list', ['limit' => 200]);
$this->set(compact('orcamento', 'clientes', 'users', 'veiculos_disponiveis'));
$this->set('_serialize', ['orcamento']);
}
when running I get the following error: Unknown finder method “listarVeiculosDisponiveis”
Where can I be wrong? I did as you say in the documentation