Relation between table A and B returns error because it calls data from table C in Cakephp

Asked

Viewed 45 times

0

I am 3 days banging head with a problem: I have some tables in the system and this error happens on the most unlikely screens.

I’ll give you the latest example:

2015-03-13 16:37:51 Error: [pdoexception] SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Cadrepresentante.id' in 'field list' Request URL: /Lhasa/auxiliar/situacao_banco/edit/18
#8 C: xampp htdocs Lhasa app Controller Situacaobancocontroller.php(87): Model->read(NULL, '18')
#9 [Internal Function]: Situacaobancocontroller->auxiliar_edit('18')

The Auxsituacaobanco table has $hasMany connection with Cadproposta, but no connection with Cadrepresentante! If I remove the link with Cadproposta in the model of Auxsituacaobanco, stop giving the editing error, but ai in Cadproposta that, has link $belongsTo, begins to give error of Auxsituacaobanco.

I don’t know what else to do to solve this problem!

Auxsituacaobanco:

public $hasMany = array(
    'CadProposta' => array(
        'className' => 'CadProposta',
        'foreignKey' => 'aux_situacao_banco_id',
    )
);

Cadproposta

public $belongsTo = array(
...
    'AuxSituacaoBanco' => array(
        'className' => 'AuxSituacaoBanco',
        'foreignKey' => 'aux_situacao_banco_id',
    ),
...
);

1 answer

0

You did not put there but probably the model Cadproposta should have a belongsTo association with Cadrepresentante

'CadRepresentante' => array(
        ....
)

adds this line

'CadRepresentante' => array(
       'fields' => array('CadRepresentante.id'),
)

There’s one other thing you can do if you don’t need the proposal data in the Auxsituacanco in the first line of the Edit function within the controller you can leave the recursion of the model in -1 so it won’t search for any relationship data. $this->Auxsituacaobanco->recursive = -1;

http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive

Browser other questions tagged

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