Motivation
ActiveRecord currently has no convenient way to see which values have been changed since the last record instantiation, reload, or save. This patch allows for the ability to monitor which attributes have changed.
Advantages
One major advantage to this incorporated into the code is increased efficiency in the update method. Before this patch, ActiveRecord will send an SQL query to update all fields, whether or not their values have changed. For small records this is okay, but for large records (tables with 8kb+ fulltext fields) this can be inefficient when only something like an froeign key id is modified. This patch will use the attribute_changed? method to only throw modified attributes and their values into the UPDATE SQL statement.
In addition to SQL optimization, users now have the ability to keep tabs on what data was modified from an existing record, which can be very helpful with form based input.
API
The following two public methods are implemented for use by the programmer:
# Returns true if attribute was modified since last read/reload/save
def attribute_changed?(attr_name)
# Returns an array of modified attributes
def changed_attributes
These methods can be incorporated into existing code for better management of attribute values.