Permalink
Browse files

Dup should reset the timestamps as it is considered a new record

  • Loading branch information...
1 parent 47f39d2 commit c17cb7326d6af7c4226e955abd3f89db95fabb33 @franckverrot franckverrot committed with tenderlove Nov 24, 2010
Showing with 11 additions and 0 deletions.
  1. +11 −0 activerecord/lib/active_record/base.rb
@@ -1625,6 +1625,7 @@ def initialize_dup(other)
ensure_proper_type
populate_with_current_scope_attributes
+ clear_timestamp_attributes
@fxn

fxn Nov 24, 2010

Owner

The docs say this is a shallow copy, which is not totally true.

I think the patch would be more complete if the RDoc of #dup documented these details.

end
# Returns +true+ if the record is read only. Records loaded through joins with piggy-back
@@ -1831,6 +1832,16 @@ def populate_with_current_scope_attributes
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

0 comments on commit c17cb73

Please sign in to comment.