Tags

, , ,

Let’s say you have an application, where users can place votes for their favorite products and you’d like to increment the current number of votes by one.

It’s very easy by using updateAll:

$this->Product->updateAll(
array(
  'Product.vote' => 'Product.vote+1'
),
array('Product.id' => 40));

You may want to restrict Product model by using unbindModel, containable, etc.

Also, you don’t have to pass in the second argument to updateAll, if you wish to update all records in your table.