From de05e2fb15ee4fd521aae202eb4517ae05114c28 Mon Sep 17 00:00:00 2001 From: Jon Leighton <j@jonathanleighton.com> Date: Mon, 24 Jan 2011 20:47:06 +0000 Subject: Abstract load_target conditional logic --- .../lib/active_record/associations/association_collection.rb | 2 +- .../lib/active_record/associations/association_proxy.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 3c939b0ef0..95526be82f 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -359,7 +359,7 @@ module ActiveRecord end def load_target - if (!@owner.new_record? || foreign_key_present?) && !loaded? + if find_target? targets = [] begin diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 59b0c54f2f..ead2c5ede2 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -226,18 +226,19 @@ module ActiveRecord # ActiveRecord::RecordNotFound is rescued within the method, and it is # not reraised. The proxy is \reset and +nil+ is the return value. def load_target - if !loaded? && (!@owner.new_record? || foreign_key_present?) && target_klass - @target = find_target - end - + @target = find_target if find_target? loaded - @target + target rescue ActiveRecord::RecordNotFound reset end private + def find_target? + !loaded? && (!@owner.new_record? || foreign_key_present?) && target_klass + end + def interpolate_sql(sql, record = nil) @owner.send(:interpolate_sql, sql, record) end -- cgit v1.2.3