开发者

With cakePHP, can I increment the value of a column without reading it's value first?

I'd like to increment the value of a column in cakePHP. Is there a way to have cakePHP write this?

UPDATE `gigs` SET `visits` = visits+1 WHERE `gigs`.`id` = 1

I tried this:

function addVisit($id){
    $this->id = $id;
    $this->saveField('visits', 'visits+1');
}

but cakePHP adds quotes around visits+1.

UPDATE `gigs` SET `visits` = 'visits+1' WHERE `gigs`.`id` = 1

I tr开发者_开发问答ied double quotes, results the same.


$this->updateAll(array(), array('Model.field + 1'))

or

$this->updateAll(null, array('Model.field + 1'))

one of them should work, saveField does not allow sql fragments, updateAll does

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜