]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
close, but still no cigar
authorChris Withers <chris@simplistix.co.uk>
Tue, 13 Apr 2010 00:55:54 +0000 (01:55 +0100)
committerChris Withers <chris@simplistix.co.uk>
Tue, 13 Apr 2010 00:55:54 +0000 (01:55 +0100)
lib/sqlalchemy/ext/declarative.py

index de2cbe5736adf613acc719ae59846b2d68af5c7a..1ca2616eabec69e7fe1344ad708ec39ecf09a5c0 100755 (executable)
@@ -537,38 +537,37 @@ def _as_declarative(cls, classname, dict_):
     column_copies = dict()
     
     mapper_args ={}
-    propagate = True
     table_args = None
+    inherited_table_args = False
     tablename = None
 
     for base in cls.__mro__:
-        if _is_mapped_class(base):
-            propagate = False
-        else:
+        if not _is_mapped_class(base):
             for name,obj in vars(base).items():
                 if name == '__mapper_args__':
                     if not mapper_args:
                         mapper_args = cls.__mapper_args__
-                elif propagate:
-                    if name == '__table_args__':
-                        if not table_args:
-                            table_args = cls.__table_args__
-                    elif name == '__tablename__':
-                        if not tablename:
-                            tablename = cls.__tablename__
-                    elif base is not cls:
-                        if isinstance(obj, Column):
-                            if obj.foreign_keys:
-                                raise exceptions.InvalidRequestError(
-                                    "Columns with foreign keys to other columns "
-                                    "are not allowed on declarative mixins at this time."
-                                )
-                            if name not in dict_:
-                                dict_[name]=column_copies[obj]=obj.copy()
-                        elif isinstance(obj, RelationshipProperty):
+                elif name == '__tablename__':
+                    if not tablename:
+                        tablename = cls.__tablename__
+                elif name == '__table_args__':
+                    if not table_args:                        
+                        table_args = cls.__table_args__
+                        if base is not cls:
+                            inherited_table_args = True
+                elif base is not cls:
+                    if isinstance(obj, Column):
+                        if obj.foreign_keys:
                             raise exceptions.InvalidRequestError(
-                                                "relationships are not allowed on "
-                                                "declarative mixins at this time.")
+                                "Columns with foreign keys to other columns "
+                                "are not allowed on declarative mixins at this time."
+                            )
+                        if name not in dict_:
+                            dict_[name]=column_copies[obj]=obj.copy()
+                    elif isinstance(obj, RelationshipProperty):
+                        raise exceptions.InvalidRequestError(
+                                            "relationships are not allowed on "
+                                            "declarative mixins at this time.")
 
     # make sure that column copies are used rather than the original columns
     # from any mixins
@@ -676,7 +675,7 @@ def _as_declarative(cls, classname, dict_):
         if table is None:
             # single table inheritance.
             # ensure no table args
-            if table_args is not None and table_args:
+            if table_args and not inherited_table_args:
                 raise exceptions.ArgumentError(
                     "Can't place __table_args__ on an inherited class with no table."
                     )