gist: 1678 Download_button fork
public
Public Clone URL: git://gist.github.com/1678.git
Diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index a28be9e..9c44eb9 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -206,7 +206,11 @@ module ActiveRecord
       end
 
       def empty?
- size.zero?
+ if loaded? || @reflection.options[:counter_sql]
+ size.zero?
+ else
+ !exists?({})
+ end
       end
 
       def any?
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index d5a1c5f..ab842b4 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -137,7 +137,7 @@ module ActiveRecord
       end
 
       def empty?
- @found ? @found.empty? : count.zero?
+ @found ? @found.empty? : !exists?({})
       end
 
       def any?

Owner

tarmo

Revisions