Overriding ActiveRecord's find method
1
jeremec
From time to time you may have reasons to override the default find method that ActiveRecord provides. In this example, we'll store a side-copy of the record attributes so that we have some basis for discovering changes to the data.
note: this will not override dynamic finders such as find_by_id
note: this will not override dynamic finders such as find_by_id
class User < ActiveRecord::Base
attr_accessor :original_values
def self.find(*options)
results = super(*options)
results.each do |result|
result.original_values = result.attributes
end
return results
end
end






There are currently no comments for this snippet.