aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb2
-rwxr-xr-xactiverecord/test/associations_test.rb9
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 0a27f18262..d2d4c08b5e 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that calling HasOneProxy#build_model repeatedly would cause saving to happen #4058 [anna@wota.jp]
+
* Added Sybase database adapter that relies on the Sybase Open Client bindings (see http://raa.ruby-lang.org/project/sybase-ctlib) #3765 [John Sheets]. It's almost completely Active Record compliant, but has the following caveats:
* Does not support DATE SQL column types; use DATETIME instead.
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index d07323a869..65f584c6f9 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -34,7 +34,7 @@ module ActiveRecord
@owner.clear_association_cache
else
@target[@reflection.primary_key_name] = nil
- @target.save unless @owner.new_record?
+ @target.save unless @owner.new_record? || @target.new_record?
end
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 79c7cc8120..c6cf7807fa 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -158,6 +158,15 @@ class HasOneAssociationsTest < Test::Unit::TestCase
assert_equal "can't be empty", account.errors.on("credit_limit")
end
+ def test_build_association_twice_without_saving_affects_nothing
+ count_of_account = Account.count
+ firm = Firm.find(:first)
+ account1 = firm.build_account("credit_limit" => 1000)
+ account2 = firm.build_account("credit_limit" => 2000)
+
+ assert_equal count_of_account, Account.count
+ end
+
def test_create_association
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save