Using scope, defined in parent model, inside it's child (STI pattern)

Posted by Anton on Stack Overflow See other posts from Stack Overflow or by Anton
Published on 2012-09-17T14:49:04Z Indexed on 2012/09/17 15:38 UTC
Read the original article Hit count: 169

Filed under:
|
|

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?...

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails-3