Here is a test. It's possible the failure is because the provided example
uses a mixin, while i am declaring directly on the base class.
from sqlalchemy import *
from sqlalchemy.ext.declarative import (declarative_base,
declared_attr, has_inherited_table)
Base = declarative_base()
class
The code referenced in the above post:
@declared_attr
def __mapper_args__(cls):
if not has_inherited_table(cls):
return {'polymorphic_on': 'discriminator'}
else:
return {'polymorphic_identity': cls.__name__}
has broken between 0.7.9 and 0.8.0, now that
Well thats the thing, my users will determine the data structure
(graphically) and it is hard to predict what they will come up with.
On the other hand, I am only building a prototype at the moment, so
speed issues (if not easily solved) will have to wait.
I'll stick with joined inheritance for
building SQLAlchemy apps graphically, that's extremely challenging good luck !
On May 1, 2012, at 5:19 AM, lars van gemerden wrote:
Well thats the thing, my users will determine the data structure
(graphically) and it is hard to predict what they will come up with.
On the other hand, I am
Ok, so speed might become an issue for me as well;
Do you think a similar metaclass approach would work for concrete
inheritance would work without major drawbacks (before i do a major
overhaul)?
Is there any indication about how much faster concrete inheritance is,
compared to joined
concrete inheritance is very challenging overall, if you expect there to be any
kind of polymorphic interaction between the classes. if you want to query
polymorphically then speed will be probably worse. If you can do without
polymorphic and stick to each subclass directly it wont have
this is the testcase:
from sqlalchemy import *
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.ext.declarative import declarative_base, declared_attr
engine = create_engine('sqlite:///:memory:', echo=False)
Base = declarative_base(bind = engine)
Session = sessionmaker(bind =
On Apr 20, 2012, at 4:59 AM, lars van gemerden wrote:
this is the testcase:
What am i missing?
the issue here is one of Python inheritance mechanics. Declarative calls upon
@declared_attr in terms of the class, that is, we look through the class to
find each @declared_attr, but when
Ok, thank you, that helps, but now i cannot inherit from Engineer, as in:
class BaseMixin(object):
discriminator = Column(String(50))
@declared_attr
def __tablename__(cls):
return cls.__name__
@declared_attr
def id(cls):
return Column(Integer, primary_key =
Hi Mike,
How about this approach with a custom metaclass; so far it works and seems
the cleanest to me:
from sqlalchemy import *
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.ext.declarative import declarative_base,
has_inherited_table, DeclarativeMeta
engine =
On Apr 20, 2012, at 8:51 AM, lars van gemerden wrote:
Ok, thank you, that helps, but now i cannot inherit from Engineer, as in:
class BaseMixin(object):
discriminator = Column(String(50))
@declared_attr
def __tablename__(cls):
return cls.__name__
11 matches
Mail list logo