from elixir import *
class Foo(Entity):
#some common functionality here
has_field('foo_field', DateTime)
class Bar(Foo):
has_field('bar_field', Unicode)
class Baz(Foo):
has_field('baz_field', Numeric)
metadata.connect("sqlite:///:memory:")
metadata.engine.echo = True
metadata.create_all()
And this is the SQL that gets outupt:
CREATE TABLE inheritance_foo (
foo_field TIMESTAMP,
id INTEGER NOT NULL,
bar_field TEXT,
baz_field NUMERIC(10, 2),
PRIMARY KEY (id)
)
Am I doing something wrong, or has someone figured this problem out
already?
Thanks,
jeff
the phenomenon you just discovered is called "single-table
inheritance"
and is meant to work this way. We're all aching for true polymorphic
multitable inheritance (with one table for each subclass), but no one
implemented it yet. The first try to do this - a couple of months ago
-
ended in a mess.
If you really need multitable inheritance, you might try stepping one
level down and do it manually through SQLAlchemy for now.
Hope that helped,
Daniel