CakePHP 2.5 model generates JOIN column that does not exist

0

Good morning

I'm using cakePHP 2.5 and I have a table of vehicles and an address for vehicles.

There is no vehicle_id column but a JOIN is generated that uses it instead of using vei_id that was explicitly indicated in conditions: 'conditions' => 'VeiculoEndereco.vei_id = Veiculo.vei_id'

Being generated in the wrong way:

(VeiculoEndereco.veiculo_id = Veiculo.vei_id) 

In the Vehicle model I have:

public $hasOne = array(
            'VeiculoEndereco' => array(
                'className'  => 'VeiculoEndereco',
                'type'=>'LEFT',
                'foreignkey' => 'vei_id',
                'conditions' => 'VeiculoEndereco.vei_id = Veiculo.vei_id'
            )
    );

E In the models of the Vehicle Address I have:

public $belongsTo = array(
        'Veiculo' => array(
            'className' => 'Veiculo',
            'foreignKey' => 'vei_id',
            'conditions' => 'VeiculoEndereco.vei_id = Veiculo.vei_id' 
        ),);

 LEFT JOIN veiculo_enderecos VeiculoEndereco ON (VeiculoEndereco.vei_id = Veiculo.vei_id AND VeiculoEndereco.veiculo_id = Veiculo.vei_id) 

How can I delete this query with the wrong column from JOIN? ( VeiculoEndereco.veiculo_id = Veiculo.vei_id ) and keep only the correct JOIN ( VeiculoEndereco.vei_id = Veiculo.vei_id )?

Even explicitly indicating conditions: 'conditions' => 'VeiculoEndereco.vei_id = Veiculo.vei_id' is still generated query per column that does not exist: **VeiculoEndereco.vei_id** = Veiculo.vei_id

    
asked by anonymous 13.02.2017 / 14:30

0 answers