diff options
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/inner_join_association_test.rb | 2 |
3 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 60f2726a6e..0227c21489 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -244,9 +244,17 @@ module ActiveRecord 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.zero? : c.empty? + end end + + # Returns true if there are any records. def any? if block_given? diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index fa54eb28b4..498a4e8144 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1188,8 +1188,6 @@ class EagerAssociationTest < ActiveRecord::TestCase end 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 diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb index 9fe5ff50d9..dffee42e7d 100644 --- a/activerecord/test/cases/associations/inner_join_association_test.rb +++ b/activerecord/test/cases/associations/inner_join_association_test.rb @@ -70,7 +70,7 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase end 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" end |