diff options
author | Jamis Buck <jamis@37signals.com> | 2007-01-11 18:04:47 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2007-01-11 18:04:47 +0000 |
commit | c398e83893121d02d7f99636cafb3382a21347c2 (patch) | |
tree | 7effb0e4a8fee7a87370ec03c7e8877232bab333 /activerecord/lib | |
parent | ba1225c72b7d139e2705461a08325ee1ea7c0cda (diff) | |
download | rails-c398e83893121d02d7f99636cafb3382a21347c2.tar.gz rails-c398e83893121d02d7f99636cafb3382a21347c2.tar.bz2 rails-c398e83893121d02d7f99636cafb3382a21347c2.zip |
fix regression in has_one#create, that caused instances thus created to be orphaned
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5881 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index bb541152c1..8d24c43a1f 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -7,6 +7,10 @@ module ActiveRecord end def create(attrs = {}, replace_existing = true) + # make sure we load the target first, if we plan on replacing the existing + # instance. Otherwise, if the target has not previously been loaded + # elsewhere, the instance we create will get orphaned. + load_target if replace_existing record = @reflection.klass.with_scope(:create => construct_scope[:create]) { @reflection.klass.create(attrs) } if replace_existing |