diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-24 20:47:06 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-01-30 11:56:41 +0000 |
commit | de05e2fb15ee4fd521aae202eb4517ae05114c28 (patch) | |
tree | a59226ca147aec24ebcbbd10dd01f02e902ff108 | |
parent | d392c67d2c614644d678627e6cd0124878982fc7 (diff) | |
download | rails-de05e2fb15ee4fd521aae202eb4517ae05114c28.tar.gz rails-de05e2fb15ee4fd521aae202eb4517ae05114c28.tar.bz2 rails-de05e2fb15ee4fd521aae202eb4517ae05114c28.zip |
Abstract load_target conditional logic
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 2 | ||||
-rw-r--r-- | activerecord/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 |