Joachim Glauche wrote:
I've an abstract class as subclass of ActiveRecord::Base . Like this:
class SomeAbstractModel < ActiveRecord::Base
self.abstract_class = true
I've a table Foo with a column "type", since I've subclasses of Foo.
If this class is defined like this
class Foo < ActiveRecord::Base
a simple select produces this query:
SELECT * FROM foo WHERE (foo."id" = 1)
If I change the superclass of Foo to my Abstract Model:
class Foo < SomeAbstractModel
the simple select produces now a different query
SELECT * FROM foo WHERE (foo."id" = 1) AND ( (foo."type" = 'Foo' ) )
This leads to my problem, since I've some rows where the type is NULL.
Why does ActiveRecord behave like that? Well,
Foo.superclass.abstract_class? returns true. Any thoughts?
I have a patch to remove abstract classes from STI find conditions:
However this is just for the efficiency boost. Your type field
should never be NULL if you're only creating non-abstract classes
in the STI hierarchy, unless it's a legacy issue.