aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-07-21 15:06:23 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-21 15:06:23 +0200
commit71312443133c6bbcc518d594789f19a213369f2a (patch)
tree5467bda46b542622d08d12dce892f2ad93204743 /activerecord
parentd77c3b669ce052234868b3d8e4f066e1baf9dbd5 (diff)
downloadrails-71312443133c6bbcc518d594789f19a213369f2a.tar.gz
rails-71312443133c6bbcc518d594789f19a213369f2a.tar.bz2
rails-71312443133c6bbcc518d594789f19a213369f2a.zip
Ensure default_scope can be overwriten by association conditions.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/relation_scoping_test.rb5
-rw-r--r--activerecord/test/models/person.rb1
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index fdf4536bc0..a50a4d4165 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -259,6 +259,11 @@ class HasManyScopingTest< ActiveRecord::TestCase
assert_equal [magician], people(:michael).bad_references
end
+ def test_should_default_scope_on_associations_is_overriden_by_association_conditions
+ person = people(:michael)
+ assert_equal [], people(:michael).fixed_bad_references
+ end
+
def test_should_maintain_default_scope_on_eager_loaded_associations
michael = Person.where(:id => people(:michael).id).includes(:bad_references).first
magician = BadReference.find(1)
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index be7463f7c8..951ec93c53 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -5,6 +5,7 @@ class Person < ActiveRecord::Base
has_many :references
has_many :bad_references
+ has_many :fixed_bad_references, :conditions => { :favourite => true }, :class_name => 'BadReference'
has_many :jobs, :through => :references
has_one :favourite_reference, :class_name => 'Reference', :conditions => ['favourite=?', true]
has_many :posts_with_comments_sorted_by_comment_id, :through => :readers, :source => :post, :include => :comments, :order => 'comments.id'