Search code examples
mysqlcakephpmysql-error-1054

CakePHP, injects "LEFT JOIN" (mentioning fields in an associated model) into my update attempts


This is driving me crazy, I am trying to do something like:

$this->data = $this->Prox->read('proxy',$currentgetdata); 
                    $this->data['Prox']['checked'] = 2;
                    $this->Prox->save();

where I have a model association of:

class Prox extends AppModel {
    var $name = 'Prox';
    var $primaryKey = 'id';
    ######## Define Model Associations #########
    var $belongsTo = array('Proxylink' => array('className' => 'Proxylink'));
}

But I get an error of:

SELECT `Prox`.`proxy` FROM `proxes` AS `Prox` LEFT JOIN `proxylinks` AS `Proxylink` ON (`Prox`.`proxylink_id` = `Proxylink`.`id`) WHERE `Prox`.`id` = '58.22.101.239:808' LIMIT 1

1054: Unknown column 'Prox.proxylink_id' in 'on clause'

I don't get why its putting this into the query "LEFT JOIN proxylinks AS Proxylink ON (Prox.proxylink_id = Proxylink.id)" and I have been unable to find any documentation on why its doing this, its as if it HAS to try to include a non-existant hybrid of a field from my associated model and my current model on each query, which I find extremely bizarre.. any advice is appreciated on what I can do to get my save / update queries to work.


Solution

  • If you have belongsTo association your 'prox' table must have 'proxylink_id' field.

    If you don't want associative models to be joined you must set 'recursive' option to -1.