Merge pull request #12084 from Ben-M/3-2-stable

Fix STI scopes using benolee's suggestion. Fixes #11939
This commit is contained in:
Aaron Patterson
2013-10-03 11:14:19 -07:00
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