From c17cb7326d6af7c4226e955abd3f89db95fabb33 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Wed, 24 Nov 2010 16:32:41 +0800 Subject: Dup should reset the timestamps as it is considered a new record --- activerecord/lib/active_record/base.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d2fa3bed35..49b30f4779 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1625,6 +1625,7 @@ MSG ensure_proper_type populate_with_current_scope_attributes + clear_timestamp_attributes end # Returns +true+ if the record is read only. Records loaded through joins with piggy-back @@ -1831,6 +1832,16 @@ MSG create_with.each { |att,value| self.respond_to?(:"#{att}=") && self.send("#{att}=", value) } if create_with end end + + # Clear attributes and changged_attributes + def clear_timestamp_attributes + %w(created_at created_on updated_at updated_on).each do |attribute_name| + if self.has_attribute?(attribute_name) + self[attribute_name] = nil + self.changed_attributes.delete(attribute_name) + end + end + end end Base.class_eval do -- cgit v1.2.3