diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2006-08-16 16:05:48 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2006-08-16 16:05:48 +0000 |
commit | ae74e8e9feba99b84f5e431239dc6a2039ad5793 (patch) | |
tree | fc9ea426fe47e5669bcdef14adb807e371f7e00e /activerecord/lib/active_record/associations | |
parent | 14101c7b40c2e04303cb497eb60996add2de645f (diff) | |
download | rails-ae74e8e9feba99b84f5e431239dc6a2039ad5793.tar.gz rails-ae74e8e9feba99b84f5e431239dc6a2039ad5793.tar.bz2 rails-ae74e8e9feba99b84f5e431239dc6a2039ad5793.zip |
Fixed a bug which would cause .save to fail after trying to access a empty has_one association on a unsaved record.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4773 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index a94daccd34..c093e40ca0 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -119,21 +119,20 @@ module ActiveRecord private def method_missing(method, *args, &block) - load_target - @target.send(method, *args, &block) + if load_target + @target.send(method, *args, &block) + end end def load_target - if !@owner.new_record? || foreign_key_present - begin - @target = find_target unless loaded? - rescue ActiveRecord::RecordNotFound - reset - end + if !loaded? and (!@owner.new_record? || foreign_key_present) + @target = find_target end - loaded - target + @loaded = true + @target + rescue ActiveRecord::RecordNotFound + reset end # Can be overwritten by associations that might have the foreign key available for an association without |