I'm having problems while searching my view method, where I have the following search:
public function view($id = null) {
if (!$this->Setor->exists($id)) {
throw new NotFoundException(__('Parâmetro inválido!'));
}
$options = array('conditions' => array('Setor.' . $this->Setor->primaryKey => $id));
$this->set('setor', $this->Setor->find('first', $options));
}
I have the result in the debug:
array(
(int) 0 => array(
'Setor' => array(
'id' => (int) 1,
'nome' => 'Diretoria de Modernização Administrativa',
'secretaria_id' => (int) 2
),
'Secretaria' => array(
'id' => (int) 2,
'codigo' => '00004210',
'nome' => 'Secretaria de Estado de Planejamento'
),
'Veiculo' => array()
)
The problem is that nothing is being listed in Vehicle, but I know there is related data. When I search the Vehicle, it returns me to the related Sectors. But not the other way around.
My Industry model is defined as follows:
public $belongsTo = array(
'Secretaria' => array(
'className' => 'Secretaria',
'foreignKey' => 'secretaria_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Status' => array(
'className' => 'Status',
'foreignKey' => 'status_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasAndBelongsToMany = array(
'Veiculo' => array(
'className' => 'Veiculo',
'joinTable' => 'setores_veiculos',
'foreignKey' => 'setor_id',
'associationForeignKey' => 'veiculo_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
)
);
The Vehicle Model:
public $belongsTo = array(
'TipoVeiculo' => array(
'className' => 'TipoVeiculo',
'foreignKey' => 'tipo_veiculo_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Status' => array(
'className' => 'Status',
'foreignKey' => 'status_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasMany = array(
'Device' => array(
'className' => 'Device',
'foreignKey' => 'veiculo_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
public $hasAndBelongsToMany = array(
'Setor' => array(
'className' => 'Setor',
'joinTable' => 'setores_veiculos',
'foreignKey' => 'veiculo_id',
'associationForeignKey' => 'setor_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
),
'Condutor' => array(
'className' => 'Condutor',
'joinTable' => 'condutores_veiculos',
'foreignKey' => 'veiculo_id',
'associationForeignKey' => 'condutor_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
)
);
Even with Contain, relationships with vehicles are not returned.
Any suggestions?