开发者

use no join. cake php

开发者 https://www.devze.com 2023-02-21 19:45 出处:网络
I have the following code. var $uses = array(\'TABLE1\',\'TABLE2\',\'TABLE3\'); function test() { $this->Table1->updateAll(

I have the following code.

var $uses = array('TABLE1','TABLE2','TABLE3');

function test() {

 $this->Table1->updateAll(
        array('Table1.field1' => 'some value'),
        array('Table1.field1 ' => 'some condition')
            );
......
.....

problem is that when I try to update only one table...Table1, it joins other tables with it.

UPDATE 
    `Table1`  
LEFT JOIN
    `开发者_如何学PythonTable2`  
ON 
    (`Table1`.`id` = `Table2`.`uid`) 
LEFT JOIN 
    `Table3`  
ON 
    (`Table1`.`Table3_id` = `Table3`.`id`) 
SET 
    `Table1`.`field1` = 1  
WHERE 
    some condition....... 

How can I not join the table and run update only on Table1?

Edit:

I used this but did not work :

$this->Table1->unBindModel(array(hasMany => array('Table2', 'Table3')));


firstly, stop using $uses. it will only cause you more pain than needed.

to avoid the joins use Model::unbindModel(array('relationType' => array('Relation')) http://book.cakephp.org/view/1045/Creating-and-Destroying-Associations-on-the-Fly


Try setting your recursive level to -1. I'm not sure whether this affects Update calls but it's worth a try.

$this->Table1->recursive = -1;
$this->Table1->updateAll(...);
0

精彩评论

暂无评论...
验证码 换一张
取 消