aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-01-18 11:25:00 +0000
committerJon Leighton <j@jonathanleighton.com>2013-01-18 11:25:00 +0000
commit5f759ff063b8ed054cdde0ed4f3593ef89fe59b7 (patch)
treeab3bbb209cddd74a71966cd213e59571f585e9f2 /activerecord
parente8d80f73996bc19b2fab46c7519c384ce96f1928 (diff)
downloadrails-5f759ff063b8ed054cdde0ed4f3593ef89fe59b7.tar.gz
rails-5f759ff063b8ed054cdde0ed4f3593ef89fe59b7.tar.bz2
rails-5f759ff063b8ed054cdde0ed4f3593ef89fe59b7.zip
CollectionProxy should be default scoped
Fixes #8795
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb1
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb5
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 33dce58982..e93e700c93 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -33,6 +33,7 @@ module ActiveRecord
def initialize(klass, association) #:nodoc:
@association = association
super klass, klass.arel_table
+ self.default_scoped = true
merge! association.scope(nullify: false)
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 28400970fb..2aa3ecb108 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1712,4 +1712,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 0, post.comments.count
end
end
+
+ test "collection proxy respects default scope" do
+ author = authors(:mary)
+ assert !author.first_posts.exists?
+ end
end