[英]saving relative values with cakephp
In MySQL I can do the following: 在MySQL中,我可以执行以下操作:
UPDATE table SET field=field+1 WHERE id=123
How do I do the same while using the CakePHP approach? 使用CakePHP方法时该如何做?
Tried the following: 尝试了以下内容:
$this->Model->id = 123;
$this->Model->save(array(
'field' => '`field`+1',
));
The article saving-your-data.html doesn't seem to cover that. 文章save-your-data.html似乎没有涵盖这一点。
Also searched for cakephp+update+relative , found nothing relevant. 还搜索cakephp + update + relative ,没有发现任何相关内容。
UPDATE Right now I'm doing a direct update, it works but I was thinking there might be a better way 更新现在我正在直接进行更新,它可以工作,但是我认为可能会有更好的方法
$this->Model->query("UPDATE ".$this->Model->useTable." SET field=field+1 WHERE id=123");
$this->Model->updateAll(
array('Model.count' => 'Model.count + 1'),
array('Model.id' => 1)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.