Thursday, December 27, 2007

ActiveRecord partial updates

ActiveRecord updates all the columns when you save the object, without bothering to see if the column was changed or not.

Pratik Naik has given the solution for partial updates on changes.

http://m.onkey.org/2007/12/18/partial-updates

Make sure that you use optimistic locking.

Active Records support optimistic locking if the field lock_version is present. Each update to the record increments the lock_version column and the locking facilities ensure that records instantiated twice will let the last one saved raise a StaleObjectError if the first was also updated.

No comments: