Hello, I've created a single table inheritance hierarchy where SpecialThing inherits from BasicThing.
When I session.query(BasicThing).count() the correct count is returned,
but session.query(SpecialThing).count() returns the count for
BasicThing. In other words, when issuing .count() the 'WHERE
discriminatorfield='something' clause disappears from the query.
I've attached the small test program showing the problem:
there are 4 basic things:
1 B first basicthing
2 B second basicthing
3 S first specialthing
4 S second specialthing
there are 4 special things:
3 S first specialthing
4 S second specialthing
Am I missing something, or is this a bug, or...?
Oh, all this on sqlalchemy-0.4.4.
Thanks,
Dieter
#!/usr/bin/env python
import sqlalchemy as sa
import sqlalchemy.orm as orm
# Python Classes to be mapped
class BasicThing(object):
def __init__(self, name):
self.name = name
class SpecialThing(BasicThing):
def __init__(self, name):
BasicThing.__init__(self, name)
# Connect, define table and map classes to table
engine = sa.create_engine('sqlite:///:memory:', echo=False)
metadata = sa.MetaData()
things = sa.Table('table',
metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('type', sa.String(1), nullable=False),
sa.Column('name', sa.String(25), nullable=False))
orm.mapper(BasicThing, things,
polymorphic_on=things.c.type,
polymorphic_identity='B')
orm.mapper(SpecialThing,
inherits=BasicThing,
polymorphic_identity='S')
metadata.create_all(engine)
# Create session
Session = orm.sessionmaker(bind=engine, autoflush=True, transactional=True)
session = Session()
# Save some things
session.save(BasicThing('first basicthing'))
session.save(BasicThing('second basicthing'))
session.save(SpecialThing('first specialthing'))
session.save(SpecialThing('second specialthing'))
session.commit()
# Query for things
print 'there are %i basic things:' % session.query(BasicThing).count()
for t in session.query(BasicThing):
print '\t', t.id, t.type, t.name
print
print 'there are %i special things:' % session.query(SpecialThing).count()
for t in session.query(SpecialThing):
print '\t', t.id, t.type, t.name
signature.asc
Description: This is a digitally signed message part
