public
Last active

default_scope select 3.1 aggregation

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
Form.count
(0.4ms) SELECT forms.id, forms.name, forms.created, forms.user_id, forms.category_id, forms.active_status, forms.read_only, forms.example_interview_id, COUNT(*) FROM `forms`
=> 1
> Form.unscoped.count
(0.2ms) SELECT COUNT(*) FROM `forms`
=> 4
> Form.unscoped.select("name").count
(0.3ms) SELECT COUNT(`forms`.`name`) FROM `forms`
=> 4
> Form.unscoped.select("name,id").count
(0.3ms) SELECT COUNT(*) FROM `forms`
=> 4
> Form.unscoped.select("name,forms.id").count
(0.5ms) SELECT COUNT(*) FROM `forms`
test.patch
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 31 32 33 34 35 36 37 38 39 40 41 42 43
From 42208a071557779f573879baf655336e84aab088 Mon Sep 17 00:00:00 2001
From: Erik Fonselius <fonsan@gmail.com>
Date: Sun, 29 May 2011 17:38:01 +0200
Subject: [PATCH] Failing test for aggregating on default_scope with select
 
---
activerecord/test/cases/relation_scoping_test.rb | 4 ++++
activerecord/test/models/developer.rb | 5 +++++
2 files changed, 9 insertions(+), 0 deletions(-)
 
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index 8f8e72f..db2c9a5 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -470,6 +470,10 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert DeveloperCalledJamis.unscoped.poor.include?(developers(:david).becomes(DeveloperCalledJamis))
assert_equal 10, DeveloperCalledJamis.unscoped.poor.length
end
+
+ def test_default_scope_select_ignored_by_aggregations
+ assert_equal DeveloperWithSelect.all.count, DeveloperWithSelect.count
+ end
def test_default_scope_order_ignored_by_aggregations
assert_equal DeveloperOrderedBySalary.all.count, DeveloperOrderedBySalary.count
diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb
index 41c52f7..98d6aa2 100644
--- a/activerecord/test/models/developer.rb
+++ b/activerecord/test/models/developer.rb
@@ -86,6 +86,11 @@ class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
end
end
+class DeveloperWithSelect < ActiveRecord::Base
+ self.table_name = 'developers'
+ default_scope select('name')
+end
+
class DeveloperOrderedBySalary < ActiveRecord::Base
self.table_name = 'developers'
default_scope :order => 'salary DESC'
--
1.7.5.1

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.