diff options
author | Chris Withers <chris@simplistix.co.uk> | 2010-04-12 23:23:27 +0100 |
---|---|---|
committer | Chris Withers <chris@simplistix.co.uk> | 2010-04-12 23:23:27 +0100 |
commit | 63fed3b0eb0d338c6208149df8774b30c6c3d68c (patch) | |
tree | e58d058a4b3fa5d6654191e70c704a815470ab85 /lib/sqlalchemy/ext/declarative.py | |
parent | 5762c9c12b71414e8f84de5d967f40dce22c4cef (diff) | |
download | sqlalchemy-63fed3b0eb0d338c6208149df8774b30c6c3d68c.tar.gz |
handle propagation
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index f4828685a..4fda6c896 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -537,35 +537,39 @@ def _as_declarative(cls, classname, dict_): column_copies = dict() mapper_args ={} + propagate = True table_args = None tablename = None - + for base in cls.__mro__: - if not _is_mapped_class(base): + if _is_mapped_class(base): + propagate = False + else: for name,obj in vars(base).items(): if name == '__mapper_args__': if not mapper_args: mapper_args = cls.__mapper_args__ - elif 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: + elif propagate: + if name == '__table_args__' and propagate: + if not table_args: + table_args = cls.__table_args__ + elif name == '__tablename__': + if not tablename and propagate: + 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): 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): - raise exceptions.InvalidRequestError( - "relationships are not allowed on " - "declarative mixins at this time.") - + "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 for k, v in mapper_args.iteritems(): |