Cakephp 2.5 model generates JOIN in column that does not exist

Asked

Viewed 24 times

0

Good morning

I’m using cakephp 2.5 and have a vehicle table and a vehicle address.

There is no live column, but a JOIN is generated that uses the input to use the ve_id that was explicitly specified in the conditions : 'conditions' => 'VeiculoEndereco.vei_id = Veiculo.vei_id'

It’s being generated wrong:

(VeiculoEndereco.veiculo_id = Veiculo.vei_id) 

In the model of the Vehicle I have :

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

And At 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 from JOIN this query with the wrong column ? (VeiculoEndereco.veiculo_id = Veiculo.vei_id) and keep only the correct JOIN (VeiculoEndereco.vei_id = Veiculo.vei_id) ?

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

  • Maybe I didn’t quite understand your doubt, but it wouldn’t just change to: VeiculoEndereco ON VeiculoEndereco.vei_id = Veiculo.vei_id?

  • it generates JOIN using the column that does not exist : Veiculoendereco.veiculo_id . There is only abbreviated vei_id. I can’t remove this JOIN id, I’m looking for how I could remove Veiculoendereco.veiculo_id from JOIN

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.