Skip to content
Browse files

Fixed Base#clone for use with PostgreSQL #565 [hanson@surgery.wisc.edu]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@519 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent daee6fd commit 431e21cb4510900619d83302d87788f5100e05ac @dhh dhh committed Feb 7, 2005
Showing with 13 additions and 4 deletions.
  1. +5 −0 activerecord/CHANGELOG
  2. +4 −4 activerecord/lib/active_record/base.rb
  3. +4 −0 activerecord/test/base_test.rb
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Fixed Base#clone for use with PostgreSQL #565 [hanson@surgery.wisc.edu]
+
+
*1.6.0* (January 25th, 2005)
* Added that has_many association build and create methods can take arrays of record data like Base#create and Base#build to build/create multiple records at once.
View
8 activerecord/lib/active_record/base.rb
@@ -832,9 +832,9 @@ def destroy
# Returns a clone of the record that hasn't been assigned an id yet and is treated as a new record.
def clone
- cloned_record = self.class.new(self.attributes)
- cloned_record.instance_variable_set "@new_record", true
- cloned_record.id = nil
+ attrs = self.attributes
+ attrs.delete(self.class.primary_key)
+ cloned_record = self.class.new(attrs)
cloned_record
end
@@ -1253,4 +1253,4 @@ def has_yaml_encoding_header?(string)
string[0..3] == "--- "
end
end
-end
+end
View
4 activerecord/test/base_test.rb
@@ -543,6 +543,10 @@ def test_clone
cloned_topic = topic.clone
cloned_topic.title["a"] = "c"
assert_equal "b", topic.title["a"]
+
+ cloned_topic.save
+ assert !cloned_topic.new_record?
+ assert cloned_topic.id != topic.id
end
def test_bignum

0 comments on commit 431e21c

Please sign in to comment.
Something went wrong with that request. Please try again.