Created
May 29, 2011 15:53
-
-
Save Fonsan/997882 to your computer and use it in GitHub Desktop.
default_scope select 3.1 aggregation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 42208a071557779f573879baf655336e84aab088 Mon Sep 17 00:00:00 2001 | |
From: Erik Fonselius <[email protected]> | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment