Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit cf1904f65bffcf6833903d4a30770eddc5713486 1 parent 59a3561
Ben Maraney Ben-M authored
2  activerecord/lib/active_record/relation/spawn_methods.rb
View
@@ -151,7 +151,7 @@ def merge_joins(relation, other)
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|
5 activerecord/test/cases/inheritance_test.rb
View
@@ -236,6 +236,11 @@ def test_inheritance_without_mapping
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
5 activerecord/test/models/company.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.