Hello,
I started playing with Concrete Table Inheritance this morning and tried to
implement a portion of my schema:
class Mixin(object):
__table_args__ = {'schema':'test'}
id = Column(Integer, primary_key=True)
class Node(ConcreteBase, Base, Mixin):
__tablename__ = 'node'
__mapper_args__ = {'polymorphic_identity':'node', 'concrete':True}
class Sample(Node, Mixin):
__tablename__ = 'sample'
__mapper_args__ = {'polymorphic_identity':'sample', 'concrete':True}
class DNA(Sample, Mixin):
__tablename__ = 'dna'
__mapper_args__ = {'polymorphic_identity':'dna', 'concrete':True}
token = Column(String(128), nullable=False)
qty = Column(Integer, nullable=False)
comments = Column(String(256))
def __init__(self, token, qty, comments=None):
self.token = token
self.qty = qty
self.comments = comments
def __repr__(self):
return """<Sample(%s, %s, Qty: %s)>""" % (self.id, self.token,
self.qty)
class RNA(Sample, Mixin):
__tablename__ = 'rna'
__mapper_args__ = {'polymorphic_identity':'rna', 'concrete':True}
token = Column(String(128), nullable=False)
qty = Column(Integer, nullable=False)
comments = Column(String(256))
def __init__(self, token, qty, comments=None):
self.token = token
self.qty = qty
self.comments = comments
def __repr__(self):
return """<RNA(%s, %s, Qty: %s)>""" % (self.id, self.token,
self.qty)
But after inserting some DNA and RNA entities...
It seems that:
session.query(Node).all()
returns an empty list whereas:
session.query(Sample).all()
returns a polymorphic list of RNAs and DNAs...
Am I missing something ?
Also:
If I declare Node as per:
class Node(AbstractConcreteBase, Base):
pass
Instead of above, I get the following error:
assert mapper is mapper.base_mapper
AssertionError
In a perfect world, I would have both Node and Sample as abstract classes
but I can't seem to get that going..
Any pointers ?
Thanks !
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/xojj7cGtMqcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.