Skip to content

Instantly share code, notes, and snippets.

@plq
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/5ed0c135222ea76d77fc to your computer and use it in GitHub Desktop.
Save plq/5ed0c135222ea76d77fc to your computer and use it in GitHub Desktop.
sqlalchemy inheritance test case
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class C(Base):
__tablename__ = 'C'
id = Column(Integer, primary_key=True)
t = Column(Integer)
__mapper_args__ = {
'polymorphic_on': t,
'polymorphic_identity': 1,
}
assert C().t == 1
class D(C):
__mapper_args__ = {
'polymorphic_identity': 2,
}
assert D().t == 2
class D2(D):
foo = 'bar'
assert D2().t == 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment