David Fitzgibbon wrote:
One of my models has a column that is updated very frequently from a separate process, so it is important that when a record is saved in rails, this column should be left alone. In the update method of the controller I have:
@record = MyModel.find(params[:id]) @record.update_attributes(params[:my_model])
params[:my_model] doesn't have a reference to the column I'm talking about, however, the UPDATE statement produced by update_attributes will still assign a value to this column.
Even though its unlikely, if the separate process updates the record in the time betweent the find, and the update, then the new value will be lost. Is there a way to prevent this from happening?
p.s. attr_protected doesn't help me
Check out optimistic locking.