aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_proxy.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-24 20:47:06 +0000
committerJon Leighton <j@jonathanleighton.com>2011-01-30 11:56:41 +0000
commitde05e2fb15ee4fd521aae202eb4517ae05114c28 (patch)
treea59226ca147aec24ebcbbd10dd01f02e902ff108 /activerecord/lib/active_record/associations/association_proxy.rb
parentd392c67d2c614644d678627e6cd0124878982fc7 (diff)
downloadrails-de05e2fb15ee4fd521aae202eb4517ae05114c28.tar.gz
rails-de05e2fb15ee4fd521aae202eb4517ae05114c28.tar.bz2
rails-de05e2fb15ee4fd521aae202eb4517ae05114c28.zip
Abstract load_target conditional logic
Diffstat (limited to 'activerecord/lib/active_record/associations/association_proxy.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb11
1 files changed, 6 insertions, 5 deletions
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