Update a row +1 in CakePHP -
i trying update row in database haven't found way in cakephp way (unless query row retrieve , update).
update mytable (field) values (field+1) id = 1 in codeigniter, have been simple as:
$this->db->set('field', 'field+1', false); $this->db->where('id', 1); $this->db->update('mytable'); how do without querying row first, retrieve value, updating row information got?
i don't think cakephp has similar method doing in normal save() on single row.
but updateall() method, updates multiple rows, support sql snippets so:
$this->widget->updateall( array('widget.numberfield' => 'widget.numberfield + 1'), array('widget.id' => 1) ); the first param array of fields/values updated, , second param conditions rows update.
apart think thing use:
$this->widget->query('your sql query here'); which lets query raw sql. [edit: not recommended bypasses orm.]
Comments
Post a Comment