dimanche 27 septembre 2015

Update multiple rows using math to add to existing value

I am trying to update multiple rows. Some rows may have a value already. So if the value in that row was 2 and I wanted to update it with an additional 4 to make total of 6. How can I do that without querying each row for it's current value? Or must I do that?

I currently have something like thing like this.

item_match = Item.where("id IN (?)", item_match_ids).to_a
item_match.update_all(quantity: quantity)

Aucun commentaire:

Enregistrer un commentaire