Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

STI should not ignore type condition while applying scopes from paren…

…t class scopes

[#4507 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 58adc6737126242d189274d83c50bcade098800a 1 parent bcf5fea
@neerajdotname neerajdotname authored josevalim committed
View
6 activerecord/lib/active_record/named_scope.rb
@@ -99,11 +99,7 @@ def scope(name, scope_options = {}, &block)
block_given? ? relation.extending(Module.new(&block)) : relation
end
- singleton_class.instance_eval do
- define_method name do |*args|
- scopes[name].call(*args)
- end
- end
+ singleton_class.send :define_method, name, &scopes[name]
end
def named_scope(*args, &block)
View
5 activerecord/test/cases/named_scope_test.rb
@@ -142,6 +142,11 @@ def test_has_many_associations_have_access_to_named_scopes
assert_equal authors(:david).posts & Post.containing_the_letter_a, authors(:david).posts.containing_the_letter_a
end
+ def test_named_scope_with_STI
+ assert_equal 3,Post.containing_the_letter_a.count
+ assert_equal 1,SpecialPost.containing_the_letter_a.count
+ end
+
def test_has_many_through_associations_have_access_to_named_scopes
assert_not_equal Comment.containing_the_letter_e, authors(:david).comments
assert !Comment.containing_the_letter_e.empty?
Please sign in to comment.
Something went wrong with that request. Please try again.