document /clean up column_property as polymorphic_on
Issue #2227
resolved
this is easy and works in 0.6, 0.7, probably even 0.5, as the expression is placed into _columntoproperty and works fine:
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import column_property, Session
Base=declarative_base()
class Parent(Base):
__tablename__ = 'p'
id = Column(Integer, primary_key=True)
type = Column(String)
substr_type = column_property(func.substr(type, 0, 4))
__mapper_args__ = {
'polymorphic_on':substr_type.columns[0](0),
'polymorphic_identity':'ABC'
}
class Child(Parent):
__tablename__ = 'c'
id = Column(Integer, ForeignKey('p.id'), primary_key=True)
__mapper_args__ = {
'polymorphic_identity':'DEF'
}
e = create_engine('sqlite://', echo=True)
Base.metadata.create_all(e)
s = Session(e)
s.add_all([ Parent(type='ABCFOO'),
Parent(type='ABCBAR'),
Child(type='DEFFOO'),
Child(type='DEFBAR'),
](
))
s.commit()
s.close()
print s.query(Parent).all()
Comments (3)
-
reporter -
reporter - changed status to duplicate
superceded by
#2238 -
reporter - removed milestone
Removing milestone: 0.7.2 (automated comment)
- Log in to comment
single inheritance needs some help with the attached patch so that polymorphic_on is reused even if not in the mapped table.