summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/declarative.py
diff options
context:
space:
mode:
authorChris Withers <chris@simplistix.co.uk>2010-04-13 01:55:54 +0100
committerChris Withers <chris@simplistix.co.uk>2010-04-13 01:55:54 +0100
commitf413a9c4113bf1c072ec760194f2e9c338bb83af (patch)
tree16b2d221c22f023ddc3365ae6758546a7103fdb6 /lib/sqlalchemy/ext/declarative.py
parent7339ee67e16f32b828ed4a44cba99cd620548d6d (diff)
downloadsqlalchemy-f413a9c4113bf1c072ec760194f2e9c338bb83af.tar.gz
close, but still no cigar
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rwxr-xr-xlib/sqlalchemy/ext/declarative.py47
1 files changed, 23 insertions, 24 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py
index de2cbe573..1ca2616ea 100755
--- a/lib/sqlalchemy/ext/declarative.py
+++ b/lib/sqlalchemy/ext/declarative.py
@@ -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."
)