Permalink
Browse files

Make AssociationCollection#include? a bit more readable

  • Loading branch information...
jonleighton committed Jan 24, 2011
1 parent 0645fd2 commit 59d54c3ebaa08c3298a36d1655a2492074ed8a87
Showing with 10 additions and 4 deletions.
  1. +10 −4 activerecord/lib/active_record/associations/association_collection.rb
@@ -297,10 +297,16 @@ def replace(other_array)
end
def include?(record)
- return false unless record.is_a?(@reflection.klass)
- return include_in_memory?(record) if record.new_record?
- load_target if @reflection.options[:finder_sql] && !loaded?
- loaded? ? @target.include?(record) : exists?(record)
+ if record.is_a?(@reflection.klass)
+ if record.new_record?
+ include_in_memory?(record)
+ else
+ load_target if @reflection.options[:finder_sql]
+ loaded? ? @target.include?(record) : scoped.exists?(record)
+ end
+ else
+ false
+ end
end
def respond_to?(method, include_private = false)

0 comments on commit 59d54c3

Please sign in to comment.