tags:

views:

28

answers:

2

Hi I want to do this.

UPDATE images SET is_primary = 0 WHERE event_id = $id

from events controller, where Event hasMany Image.

+2  A: 
$this->Event->saveAll($this->data);

See: http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo

and: http://api12.cakephp.org/class/model#method-ModelsaveAll

Alternatively, you can save the Event, then loop over and save each Image.

There is also the option of:

$this->Image->query("UPDATE images SET is_primary = 0 WHERE event_id = $id");

See: http://book.cakephp.org/view/456/query

Leo
+3  A: 
$this->Event->Image->updateAll(array('is_primary'=>0), array('Event.id'=>$id));

Check this and search for updateAll

Nik