Permalink
Browse files

Abstract load_target conditional logic

  • Loading branch information...
1 parent d392c67 commit de05e2fb15ee4fd521aae202eb4517ae05114c28 @jonleighton jonleighton committed Jan 24, 2011
@@ -359,7 +359,7 @@ def association_scope
end
def load_target
- if (!@owner.new_record? || foreign_key_present?) && !loaded?
+ if find_target?
targets = []
begin
@@ -226,18 +226,19 @@ def target_scope
# 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

0 comments on commit de05e2f

Please sign in to comment.