1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix STI scopes using benolee's suggestion. Fixes #11939

This commit is contained in:
Ben Maraney 2013-08-30 12:25:10 +03:00
parent 59a3561045
commit cf1904f65b
3 changed files with 11 additions and 1 deletions

View file

@ -151,7 +151,7 @@ module ActiveRecord
values = other.joins_values
return if values.blank?
if other.klass == relation.klass
if other.klass >= relation.klass
relation.joins_values += values
else
joins_dependency, rest = values.partition do |join|

View file

@ -236,6 +236,11 @@ class InheritanceTest < ActiveRecord::TestCase
assert_nothing_raised { s = SpecialSubscriber.new("name" => "And breaaaaathe!"); s.id = 'roger'; s.save }
end
def test_scope_inherited_properly
assert_nothing_raised { Company.of_first_firm }
assert_nothing_raised { Client.of_first_firm }
end
private
def switch_to_alt_inheritance_column
# we don't want misleading test results, so get rid of the values in the type column

View file

@ -12,6 +12,11 @@ class Company < AbstractCompany
has_many :contracts
has_many :developers, :through => :contracts
scope :of_first_firm, lambda {
joins(:account => :firm).
where('firms.id' => 1)
}
def arbitrary_method
"I am Jack's profound disappointment"
end