When I have single table inheritance, how can I use the new 'inline' 
polymorphic_load feature to only query a subset of child classes?

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Parent(Base):
__tablename__ = 'parent'

id = Column(Integer, primary_key=True)
type = Column(String(8), nullable=False)

__mapper_args__ = {
'polymorphic_on': type,
'with_polymorphic': '*'
}

class ChildOne(Parent):
one = Column(String(8))

__mapper_args__ = {
'polymorphic_identity': 'one',
'polymorphic_load': 'inline'
}

class ChildTwo(Parent):
two = Column(String(8))

__mapper_args__ = {
'polymorphic_identity': 'two'
}

if __name__ == '__main__':
e = create_engine('sqlite:///inline.db', echo=True)

Base.metadata.drop_all(e)
Base.metadata.create_all(e)

s = Session(e)

s.add_all([ChildOne(one='hahaha'), ChildTwo(two='lololol')])

s.commit()

for c in s.query(Parent).all():
print(c)

I've tried adding and removing 'with_polymorphic': '*' from the parent 
class, but it always queries ChildTwo as well

I feel like I need to set something on ChildTwo to tell it not to load, but 
nothing like this is documented

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to