diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-14 16:57:14 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-14 16:57:14 -0800 |
commit | 75e29e871e925cb7485cdbc283594d3d97871703 (patch) | |
tree | b65512992b4a76481f7be94af05e5fae8232adce | |
parent | f548054700e59ac77b2a20df96b9ebd98abed195 (diff) | |
download | rails-75e29e871e925cb7485cdbc283594d3d97871703.tar.gz rails-75e29e871e925cb7485cdbc283594d3d97871703.tar.bz2 rails-75e29e871e925cb7485cdbc283594d3d97871703.zip |
only find_target can raise the exception, so isolate the rescue around that call
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 864d84d71a..1254d68e9a 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -351,15 +351,19 @@ module ActiveRecord def load_target if !@owner.new_record? || foreign_key_present? unless loaded? + targets = [] + begin - if @target.any? - @target = merge_target_lists(find_target, @target) - else - @target = find_target - end + targets = find_target rescue ActiveRecord::RecordNotFound reset end + + if @target.any? + @target = merge_target_lists(targets, @target) + else + @target = targets + end end end |