thanks for the great test case, makes this easy.
The with_polymorphic() function is used for this kind of situation, more
common in joined inheritance but since you want to alias here, works for
single also:
Piece = with_polymorphic(Item, '*', aliased=True)
s.query(Item) \
.ou
A more complete example:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import *
Base = declarative_base()
class Item(Base):
__tablename__ = 'item'
id = Column(Integer, primary_key=True)
type = Column(String)
__mapper_args__ = {
'polymorphic_on': type,
'
A more complete example
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import *
Base = declarative_base()
class Item(Base):
__tablename__ = 'item'
id = Column(Integer, primary_key=True)
type = Column(String)
__mapper_args__ = {
'polymorphic_on': type,
'w