]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
declarartive reflection example didn't actually work for single inheritance, added...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Feb 2012 20:56:21 +0000 (15:56 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Feb 2012 20:56:21 +0000 (15:56 -0500)
examples/declarative_reflection/declarative_reflection.py

index 42d2201e1e9f0bd0d022d11a8ac8572f9645ffbe..3721493172757d1b50fe577177b7b447e45617a6 100644 (file)
@@ -1,5 +1,6 @@
 from sqlalchemy import *
 from sqlalchemy.orm import *
+from sqlalchemy.orm.util import _is_mapped_class
 from sqlalchemy.ext.declarative import declarative_base, declared_attr
 
 class DeclarativeReflectedBase(object):
@@ -35,6 +36,16 @@ class DeclarativeReflectedBase(object):
                     autoload=True, 
                     autoload_with=engine,
                     schema=table.schema)
+
+            # see if we need 'inherits' in the
+            # mapper args.  Declarative will have 
+            # skipped this since mappings weren't
+            # available yet.
+            for c in klass.__bases__:
+                if _is_mapped_class(c):
+                    kw['inherits'] = c
+                    break
+
             klass.__mapper__ = mapper(*args, **kw)
 
 if __name__ == '__main__':