Permalink
Browse files

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

  • Loading branch information...
1 parent 59a3561 commit cf1904f65bffcf6833903d4a30770eddc5713486 @Ben-M Ben-M committed Aug 30, 2013
@@ -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|
@@ -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
@@ -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

0 comments on commit cf1904f

Please sign in to comment.