title: SQLAlchemy query on Base Class including Derived Classes
body: <p>I'm using single table inheritance configuration in sqlalchemy to create several derived classes. When querying the base class the results include all derived classes as well. I'd like the results to only include the base class. </p>
  
  <p>Used example code in the sqlalchemy documentation.</p>
  
  <pre><code>from sqlalchemy import create_engine, text, func, and_, Column, Integer, String, ForeignKey, Boolean, MetaData, Table
  from sqlalchemy.orm import sessionmaker, with_polymorphic, backref, relationship
  from sqlalchemy.ext.declarative import declarative_base, declared_attr, has_inherited_table
  
  
  POSTGRES = {
      'user': 'sqlalchemy',
      'pw': 'sqlalchemy',
      'db': 'sqlalchemy',
      'host': '127.0.0.1',
      'port': '5432',
  }
  
  Base = declarative_base()
  meta = MetaData()
  
  engine = create_engine('postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES, echo=False)
  DBSession = sessionmaker(bind=engine)
  s = DBSession()
  d = {}
  
  
  ''' Create Base Classes using single table polymorphic identity column '''
  
  
  class Person(Base):
  
      __tablename__ = 'people'
  
      id = Column(Integer, primary_key=True)
      name = Column(String, nullable=False)
      discriminator = Column('type', String(50))
  
      __mapper_args__ = {'polymorphic_on': discriminator, 'polymorphic_identity': 'person'}
  
  
  class Engineer(Person):
  
      primary_language = Column(String(50))
  
      __mapper_args__ = {'polymorphic_identity': 'engineer'}
  
  
  ''' Create Empty Schema '''
  
  Base.metadata.drop_all(bind=engine)
  Base.metadata.create_all(bind=engine)
  
  ''' Create a bunch of objects '''
  
  for id in range(1, 11):
  
      s.add(Person(name='person_%s' % str(id)))
      s.add(Engineer(name='engineer_%s' % str(id)))
      s.commit()
      s.flush()
  
  print('people: %s' % s.query(Person).count())
  print('engineers: %s' % s.query(Engineer).count())
  
  ''' Person query should only have 10 results but has 20. Engineer query has 10 results. '''
  
  s.flush()
  s.close()
  
  exit()
  </code></pre>
  
  <p>Person query should have 10 results but include Engineers also.</p>