diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-06-23 19:57:49 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-06-23 19:57:49 +0100 |
commit | 87d6865bf71eb3feb5831ca541f3493aa36ee88e (patch) | |
tree | f08c74bfb942427e621ee898b2c4b1c3a3fa51c9 /activerecord/test | |
parent | 8a1319dec09672cbb1a4d6fce1db09f10c44bceb (diff) | |
download | rails-87d6865bf71eb3feb5831ca541f3493aa36ee88e.tar.gz rails-87d6865bf71eb3feb5831ca541f3493aa36ee88e.tar.bz2 rails-87d6865bf71eb3feb5831ca541f3493aa36ee88e.zip |
Apply the default scope earlier when doing calculations. Fixes #1682.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation_scoping_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index a6e08f95d0..0e158df6a0 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -498,4 +498,11 @@ class DefaultScopingTest < ActiveRecord::TestCase lowest_salary_dev = DeveloperOrderedBySalary.find(developers(:poor_jamis).id) assert_equal lowest_salary_dev, DeveloperOrderedBySalary.last end + + def test_default_scope_include_with_count + d = DeveloperWithIncludes.create! + d.audit_logs.create! :message => 'foo' + + assert_equal 1, DeveloperWithIncludes.where(:audit_logs => { :message => 'foo' }).count + end end diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 98d6aa22f7..f182a7fa97 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -91,6 +91,12 @@ class DeveloperWithSelect < ActiveRecord::Base default_scope select('name') end +class DeveloperWithIncludes < ActiveRecord::Base + self.table_name = 'developers' + has_many :audit_logs, :foreign_key => :developer_id + default_scope includes(:audit_logs) +end + class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' default_scope :order => 'salary DESC' |