2013-05-14 102 views
2

我有一个主表格Cliente。该表与另外20个表相关联。我正尝试使用下面的代码只更新表Clientee:只更新表格,但表格与另一个表格关联

$this->Cliente->updateAll(array("ec_cnpj" => $this->request->data['Cliente']['ec_cnpj'], 
            "ec_cpf" => $this->request->data['Cliente']['ec_cpf'], 
            "ec_rg" => $this->request->data['Cliente']['ec_rg'], 
            "ec_rg_org_emissor" => $this->request->data['Cliente']['ec_rg'], 
            "ec_rg_est_emissor" => $this->request->data['Cliente']['ec_rg_est_emissor'], 
            "ec_nire" => $this->request->data['Cliente']['ec_nire']), 
          array("ec_codigo"=>$this->request->data['ec_codigo'])) 

不过,蛋糕是生成查询更新所有表。我怎么做只更新客户表?

回答

4

the docs

默认情况下,updateAll()会自动加入任何属于关联 协会支持连接数据库。为了防止这种情况, 暂时解除关联。

所以,unbind对应的车型,如

$this->Cliente->unbindModel(array('hasMany' => array('table1', 'table2'))); 

阅读 “Creating and Destroying Associations on the Fly” 有更深入的了解它。

也许你会找到类似this的东西有用,但是直接从cakephp中直接得到的东西逃脱了,你必须创建一个新的函数。

+0

非常感谢您的帮助。工作得很好! – Stark 2013-05-17 17:25:10

+0

谢谢你的回答,你能不能更新最后的[链接](http://bakery.cakephp.org/articles/cornernote/2006/12/10/unbindall),好像已经死了 – 2017-01-06 14:50:55

+0

谢谢你了@Ayaou , 更新 :) – Nunser 2017-01-10 19:33:48

相关问题