aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-18 15:15:27 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-18 15:15:27 +0000
commitb09829354f4699941824f53903f4a8743fa98bd5 (patch)
tree00cd125cb0da19df1af5dc8a7ae4866e27ce4597 /activerecord
parent3e6fe858b6a785f857c6a752410107bd824747eb (diff)
downloadrails-b09829354f4699941824f53903f4a8743fa98bd5.tar.gz
rails-b09829354f4699941824f53903f4a8743fa98bd5.tar.bz2
rails-b09829354f4699941824f53903f4a8743fa98bd5.zip
Fixed the automated timestamping feature when running under Rails' development environment that resets the inheritable attributes on each request.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@212 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-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