From: Chris Withers Date: Tue, 13 Apr 2010 09:02:22 +0000 (+0100) Subject: I think I'm about to have a When Harry Met Sally moment X-Git-Tag: rel_0_6_0~23^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e191b601cc1230505ea5ade34f411c72f0f5a66;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git I think I'm about to have a When Harry Met Sally moment --- diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 1ca2616eab..0c7aa68db0 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -535,14 +535,17 @@ def _as_declarative(cls, classname, dict_): dict_ = dict(dict_) column_copies = dict() + potential_columns = dict() mapper_args ={} - table_args = None - inherited_table_args = False + table_args = inherited_table_args = None tablename = None - + parent_columns = None + for base in cls.__mro__: - if not _is_mapped_class(base): + if _is_mapped_class(base): + parent_columns = base.__table__.c.keys() + else: for name,obj in vars(base).items(): if name == '__mapper_args__': if not mapper_args: @@ -563,11 +566,17 @@ def _as_declarative(cls, classname, dict_): "are not allowed on declarative mixins at this time." ) if name not in dict_: - dict_[name]=column_copies[obj]=obj.copy() + potential_columns[name]=column_copies[obj]=obj.copy() elif isinstance(obj, RelationshipProperty): raise exceptions.InvalidRequestError( "relationships are not allowed on " "declarative mixins at this time.") + # apply inherited columns as we should + for k, v in potential_columns.items(): + if tablename or k not in parent_columns: + dict_[k]=v + if inherited_table_args and not tablename: + table_args = None # make sure that column copies are used rather than the original columns # from any mixins @@ -675,7 +684,7 @@ def _as_declarative(cls, classname, dict_): if table is None: # single table inheritance. # ensure no table args - if table_args and not inherited_table_args: + if table_args: raise exceptions.ArgumentError( "Can't place __table_args__ on an inherited class with no table." )