CakePHP updateAll() issues

In your model do something like this in your method ....

public function saveImage($type='')
{
 // I would add a test for $type
 $db = $this->getDataSource();
 $fields = array('type' => $db->value($type, 'string')); // $db->value() will format strings needed for updateAll()
 $condition = array('user_id' => $this->Auth->user('id'));

 // I would add a test for user id before running updateAll()

  $this->updateAll($fields, $conditions);

}


Found this on the manual:

The $fields array accepts SQL expressions. Literal values should be quoted manually.

Thus, the following should work:

$this->Image->updateAll(
    array('Image.type' => "'gallery'"), 
    array('Image.user_id' => $this->Auth->user('id'))
);

Tags:

Cakephp