Permalink
Browse files

Refactor AssociationCollection#include? with objects in memory

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent b951522 commit 4e93179ed3f44825c157b54517e5a256f5725a55 @carlosantoniodasilva carlosantoniodasilva committed with josevalim Sep 30, 2010
Showing with 3 additions and 4 deletions.
  1. +3 −4 activerecord/lib/active_record/associations/association_collection.rb
@@ -558,11 +558,10 @@ def fetch_first_or_last_using_find?(args)
def include_in_memory?(record)
if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
- @owner.send(proxy_reflection.through_reflection.name.to_sym).map do |source|
- source_reflection_target = source.send(proxy_reflection.source_reflection.name)
- return true if source_reflection_target.respond_to?(:include?) ? source_reflection_target.include?(record) : source_reflection_target == record
+ @owner.send(proxy_reflection.through_reflection.name.to_sym).any? do |source|
+ target = source.send(proxy_reflection.source_reflection.name)
+ target.respond_to?(:include?) ? target.include?(record) : target == record
end
- false
else
@target.include?(record)
end

0 comments on commit 4e93179

Please sign in to comment.