Using scope, defined in parent model, inside it's child (STI pattern)
- by Anton
I implement a class hierarchy using STI pattern
class A
scope :aaa, where([someField]:[someValue])
end
class B < A
end
The problem is that when I try to call something like:
B.limit(5).aaa
=> SELECT "[table]".* FROM "[table]" WHERE "[table]"."type" IN ('A') AND ([someField] = [someValue]) LIMIT 5
So I am getting 5 objects of type A, which satisfies scope :aaa
But I need to do the same with rows where type = "B"
Is there any way to use scopes from parent, without redifinning it in childs in STI pattern?
Thanks in advance
EDITED
I just discussed it with my frind and he showed me one important thing. A in not the root class of STI. IN fact whole hierarchy looks like
class O < ActiveRecord::Base
end
class A < O
scope ..... .....
end
class B < A
end
maybe the reason is in hierarchy itself?...