How do I update a cumulative field in a Rails database (using ActiveRecord or Mongoid)?
- by picardo
I want to update a field in a database table that has to have a cumulative value. So basically I need to find the current value of the field and update it using a new number.
My first inefficient try at this (in Mongoid) is:
v = Landlord.where(:name=>"Lorem")
v.update_attributes(:violations=>v.violations + 10)
Is there a simple method than making one query to read, then sum up, and another query to write?