Skip to content

Instantly share code, notes, and snippets.

@tonio
Created June 11, 2012 14:58
Show Gist options
  • Save tonio/2910483 to your computer and use it in GitHub Desktop.
Save tonio/2910483 to your computer and use it in GitHub Desktop.
FormAlchemy with model inheritance
diff --git a/formalchemy/tests/__init__.py b/formalchemy/tests/__init__.py
index 7dcacd9..c9c9d6c 100644
--- a/formalchemy/tests/__init__.py
+++ b/formalchemy/tests/__init__.py
@@ -80,6 +80,18 @@ class One(Base):
__tablename__ = 'ones'
id = Column(Integer, primary_key=True)
+class Root(Base):
+ __tablename__ = 'root'
+ id = Column(Integer, primary_key=True)
+ foo = Column('type', String(50))
+ __mapper_args__ = {'polymorphic_on': foo}
+
+class Ext(Root):
+ __tablename__ = 'ext'
+ __mapper_args__ = {'polymorphic_identity': 'ext'}
+ id = Column(Integer, ForeignKey('root.id'), primary_key=True)
+ bar = Column(String(50))
+
class Two(Base):
__tablename__ = 'twos'
id = Column(Integer, primary_key=True)
diff --git a/formalchemy/tests/test_inheritance.py b/formalchemy/tests/test_inheritance.py
new file mode 100644
index 0000000..fa0e7d3
--- /dev/null
+++ b/formalchemy/tests/test_inheritance.py
@@ -0,0 +1,15 @@
+__doc__ = r"""
+>>> from formalchemy.tests import *
+
+>>> FieldSet.default_renderers = original_renderers.copy()
+>>> hasattr(Ext, 'foo')
+True
+>>> fs = FieldSet(Ext)
+>>> fs
+<FieldSet with ['id', 'foo', 'bar']>
+
+"""
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()
Failed example:
fs
Expected:
<FieldSet with ['id', 'foo', 'bar']>
Got:
<FieldSet with ['id', 'bar']>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment