aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb4
-rwxr-xr-xactiverecord/test/associations_test.rb3
3 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 6e69f3cd6a..5b8657fa89 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that the create_x method from belongs_to wouldn't save the association properly #2042 [Florian Weber]
+
* Fixed saving a record with two unsaved belongs_to associations pointing to the same object #2023 [Tobias Luetke]
* Improved migrations' behavior when the schema_info table is empty. [Nicholas Seckar]
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index fd36c2d8ae..681bd1b88d 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -13,8 +13,8 @@ module ActiveRecord
end
def create(attributes = {})
- record = build(attributes)
- record.save
+ record = @association_class.create(attributes)
+ replace(record, true)
record
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 763b66da9b..2bbccb5c9e 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -664,6 +664,9 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
citibank = Account.create("credit_limit" => 10)
apple = citibank.create_firm("name" => "Apple")
assert_equal apple, citibank.firm
+ citibank.save
+ citibank.reload
+ assert_equal apple, citibank.firm
end
def test_building_the_belonging_object