aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-11-14 14:43:14 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-11-14 14:43:14 -0800
commit421c81bd1875eb4e163bea8ce18b1ae9c2224e7d (patch)
tree87283624cbe5b1a1e5398011424e5b74acc0af9c /activerecord/lib/active_record
parente15ea62b26e010d02459f8a2438f5a281cc1dd8f (diff)
downloadrails-421c81bd1875eb4e163bea8ce18b1ae9c2224e7d.tar.gz
rails-421c81bd1875eb4e163bea8ce18b1ae9c2224e7d.tar.bz2
rails-421c81bd1875eb4e163bea8ce18b1ae9c2224e7d.zip
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)
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation.rb10
1 files changed, 9 insertions, 1 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?