my question is pretty simple but hard to find an answer for though search engines.
I simply want to update a field in the database, using that fields old value to add another value. I'm using the following at the moment:
$this->Advertisement->saveField('total_views', '(total_views + 1)', false);
But this gives me the next query:
UPDATE `advertisement` SET `total_views` = '(total_views +1)', `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16
This is wrong and it should be:
UPDATE `advertisement` SET `total_views` = (total_views +1), `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16
The problem is where it puts (total_views +1)
between quotes.
Does anyone have an idea on how to get this working?
$this->Advertisement->updateAll(
array('Advertisement.total_views' => 'Advertisement.total_views + 1'),
array('Advertisement.id' => 1)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With