- changed milestone to 0.7.4
one polymorphic_on to rule them all
This is how it will work:
# traditional
class MyClass(Base):
# ...
type = Column(String)
__mapper_args__ = {
'polymorphic_on':type
}
# callable
class MyClass(Base):
# ...
type = Column(String)
def _discriminator(cls, mapper, context, adapted_row, row, klass):
if adapted_row[klass.type](klass.type) == 'foo':
return Bar
else:
return MyClass
__mapper_args__ = {
'polymorphic_on':_discriminator
}
# arbitrary
class MyClass(Base):
# ...
type = Column(String)
__mapper_args__ = {
'polymorphic_on':func.foo_bar(xyz)
}
# fallback identities
# we use a symbol here in case someone is already
# using '*'
from sqlalchemy.orm import DEFAULT_IDENTITY
class MyClass(Base):
# ...
type = Column(String)
__mapper_args__ = {
'polymorphic_on':type,
'polymorphic_identity':DEFAULT_IDENTITY
}
now to solve the problem of all the old with_polymorphic tests and incompatible polymorphic_ons.
polymorphic_on is unconditionally propagated if there is no built in with_polymorphic selectable, uncondititionally not propagated if there is a with_polymorphic_selectable present. Hoping that rule just works here.
Comments (7)
-
reporter -
reporter Please note
#2227for single-table inh examples -
reporter - changed milestone to 0.8.0
-
reporter one serious shortcoming here and maybe a reason to not even go the "python lambda" route is that we can't do any kind of single table row limiting.
-
reporter a lot of this is in d1cc7e7517da26521639fb22826d6e91e51c928e.
-
reporter - changed status to wontfix
this is done - the "polymorphic_on" must be evaluable in SQL, especially for single table inheritance, and with d1cc7e7517da26521639fb22826d6e91e51c928e we have that.
-
reporter - removed milestone
Removing milestone: 0.8.0b1 (automated comment)
- Log in to comment