Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix that eager loading of polymorphic associations did not work with …

…association empty?/any? predicates any more (there is still a problem when select is applied to a relation, or if you try association#exists? -- but its easier to work around)
  • Loading branch information...
commit 421c81bd1875eb4e163bea8ce18b1ae9c2224e7d 1 parent e15ea62
@dhh dhh authored
10 activerecord/lib/active_record/relation.rb
@@ -244,9 +244,17 @@ def size
def empty?
return @records.empty? if loaded?
- limit_value == 0 ? true : !exists?
+ if limit_value == 0
+ true
+ else
+ # FIXME: This count is not compatible with #select('authors.*') or other select narrows
+ c = count
+ c.respond_to?(:zero?) ? : c.empty?
+ end
# Returns true if there are any records.
def any?
if block_given?
2  activerecord/test/cases/associations/eager_test.rb
@@ -1188,8 +1188,6 @@ def test_deep_including_through_habtm
test "preloading with a polymorphic association and using the existential predicate" do
- skip 'broken test'
assert_equal authors(:david), authors(:david).essays.includes(:writer).first.writer
assert_nothing_raised do
2  activerecord/test/cases/associations/inner_join_association_test.rb
@@ -70,7 +70,7 @@ def test_find_with_implicit_inner_joins_honors_readonly_false
def test_find_with_implicit_inner_joins_does_not_set_associations
- authors = Author.joins(:posts).select('authors.*')
+ authors = Author.joins(:posts).select('authors.*').to_a
assert !authors.empty?, "expected authors to be non-empty"
assert authors.all? { |a| !a.instance_variable_defined?(:@posts) }, "expected no authors to have the @posts association loaded"

1 comment on commit 421c81b


:+1: I didn't have time to work on it this week, sorry. But I was about to revert that change too.

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