3 ms·
Does ActiveRecord (the Ruby library) support e.g. Book.where({isbn: "978-0099466031"}).update_all("copies_in_stock = copies_in_stock - 1") without breakin
by strken 7y ago
Does ActiveRecord (the Ruby library) support e.g.
Book.where({isbn: "978-0099466031"}).update_all("copies_in_stock = copies_in_stock - 1")
without breaking? It's been a long time since I've used it and I can't remember whether you have to use .execute or not.
- pmontra 7y agoProbably yes. Check the comments at https://apidock.com/rails/v6.0.0/ActiveRecord/Relation/update_all https://apidock.com/rails/v6.0.0/ActiveRecord/Relation/updat...
- petepete 7y agoJust tried it and it works fine. Feels a bit un-Railslike but it does exactly what you'd expect it to > Unit.where(ccp_id: 1).update_all("position = position + 1") Unit Update All (9.4ms) UPDATE "units" SET position = position + 1 WHERE "units"."ccp_id" = $1 => 5