Skip to content
Browse files

include_in_memory? should check against @target list in case of new r…

…ecords. [#6257 state:resolved]
  • Loading branch information...
1 parent 3667438 commit 10fa49bc1a25bd2cd25f211e2d8b1771beb58e21 @tenderlove tenderlove committed Jan 12, 2011
View
9 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
- end
- false
+ @owner.send(proxy_reflection.through_reflection.name).any? { |source|
+ target = source.send(proxy_reflection.source_reflection.name)
+ target.respond_to?(:include?) ? target.include?(record) : target == record
+ } || @target.include?(record)
else
@target.include?(record)
end
View
7 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -31,6 +31,13 @@ def setup
Reader.create :person_id => 0, :post_id => 0
end
+ def test_include?
+ person = Person.new
+ post = Post.new
+ person.posts << post
+ assert person.posts.include?(post)
+ end
+
def test_associate_existing
assert_queries(2) { posts(:thinking); people(:david) }

0 comments on commit 10fa49b

Please sign in to comment.
Something went wrong with that request. Please try again.