aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record.rb2
-rw-r--r--activerecord/lib/active_record/timestamp.rb22
3 files changed, 20 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index db2b44ac02..e9927ae980 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed the automated timestamping feature when running under Rails' development environment that resets the inheritable attributes on each request.
+
* Added Base#update_attributes that'll accept a hash of attributes and save the record (returning true if it passed validation, false otherwise).
Before:
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 36c367b78f..5c9043b094 100755
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -41,12 +41,12 @@ require 'active_record/acts/tree'
ActiveRecord::Base.class_eval do
include ActiveRecord::Validations
+ include ActiveRecord::Timestamp
include ActiveRecord::Callbacks
include ActiveRecord::Associations
include ActiveRecord::Aggregations
include ActiveRecord::Transactions
include ActiveRecord::Reflection
- include ActiveRecord::Timestamp
include ActiveRecord::Acts::Tree
include ActiveRecord::Acts::List
end
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb
index 59c72aa4a9..b267284cf8 100644
--- a/activerecord/lib/active_record/timestamp.rb
+++ b/activerecord/lib/active_record/timestamp.rb
@@ -7,19 +7,31 @@ module ActiveRecord
module Timestamp
def self.append_features(base) # :nodoc:
super
- base.before_create :timestamp_before_create
- base.before_update :timestamp_before_update
+
+ base.class_eval do
+ alias_method :create_without_timestamps, :create
+ alias_method :create, :create_with_timestamps
+
+ alias_method :update_without_timestamps, :update
+ alias_method :update, :update_with_timestamps
+ end
end
- def timestamp_before_create
+ def create_with_timestamps
write_attribute("created_at", Time.now) if record_timestamps && respond_to?(:created_at) && created_at.nil?
write_attribute("created_on", Time.now) if record_timestamps && respond_to?(:created_on) && created_on.nil?
- timestamp_before_update
+
+ write_attribute("updated_at", Time.now) if record_timestamps && respond_to?(:updated_at)
+ write_attribute("updated_on", Time.now) if record_timestamps && respond_to?(:updated_on)
+
+ create_without_timestamps
end
- def timestamp_before_update
+ def update_with_timestamps
write_attribute("updated_at", Time.now) if record_timestamps && respond_to?(:updated_at)
write_attribute("updated_on", Time.now) if record_timestamps && respond_to?(:updated_on)
+
+ update_without_timestamps
end
end