mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
Merge pull request #12084 from Ben-M/3-2-stable
Fix STI scopes using benolee's suggestion. Fixes #11939
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user