Sorry to be asking more questions, but the docs on inheritance don't get
into much details on how the properties are supposed to work.
The following code produces unexpected results:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import AbstractConcreteBase,
declarative_base
Base = declarative_base()
class Document(Base, AbstractConcreteBase):
doctype = Column('doc_type', Unicode, nullable=False)
class ActualDocument(Document):
__tablename__ = 'actual_documents'
__mapper_args__ = {'concrete': True, 'polymorphic_identity': 'actual'}
id = Column(Integer, primary_key=True)
name = Column('name_', Unicode)
configure_mappers()
for prop in class_mapper(Document).column_attrs:
print('%s (%s)' % (prop, prop.__class__.__name__))
for prop in class_mapper(ActualDocument).column_attrs:
print('%s (%s)' % (prop, prop.__class__.__name__))
Which gives me:
Document.doc_type (ColumnProperty)
Document.id (ColumnProperty)
Document.name_ (ColumnProperty)
Document.type (ColumnProperty)
ActualDocument.doctype (ColumnProperty)
ActualDocument.name (ColumnProperty)
ActualDocument.id (ColumnProperty)
I can understand Document.id (which comes from ActualDocument) and
Document.type (which I assume is the polymorphic identity) but doc_type
seems wrong to me. Why are doc_type and name_ not named doctype and name
respectively, like they are on ActualDocument? Is this a bug? Am I right in
guessing that the polymorphic union simply lacks the proper labels where
the column name differs from the attribute name?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.