diff options
Diffstat (limited to 'lib/sqlalchemy')
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 00c4aec3f..c8c464d0d 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -262,20 +262,26 @@ dictionary:: __tablename__ = 'sometable' __table_args__ = {'mysql_engine':'InnoDB'} -The other, a tuple of the form -``(arg1, arg2, ..., {kwarg1:value, ...})``, which allows positional -arguments to be specified as well (usually constraints):: +The other, a tuple, where each argument is positional +(usually constraints):: class MyClass(Base): __tablename__ = 'sometable' __table_args__ = ( ForeignKeyConstraint(['id'], ['remote_table.id']), UniqueConstraint('foo'), - {'autoload':True} ) -Note that the keyword parameters dictionary is required in the tuple -form even if empty. +Keyword arguments can be specified with the above form by +specifying the last argument as a dictionary:: + + class MyClass(Base): + __tablename__ = 'sometable' + __table_args__ = ( + ForeignKeyConstraint(['id'], ['remote_table.id']), + UniqueConstraint('foo'), + {'autoload':True} + ) Using a Hybrid Approach with __table__ ======================================= @@ -1004,14 +1010,10 @@ def _as_declarative(cls, classname, dict_): if isinstance(table_args, dict): args, table_kw = (), table_args elif isinstance(table_args, tuple): - args = table_args[0:-1] - table_kw = table_args[-1] - if len(table_args) < 2 or not isinstance(table_kw, dict): - raise exc.ArgumentError( - "Tuple form of __table_args__ is " - "(arg1, arg2, arg3, ..., {'kw1':val1, " - "'kw2':val2, ...})" - ) + if isinstance(table_args[-1], dict): + args, table_kw = table_args[0:-1], table_args[-1] + else: + args, table_kw = table_args, {} else: args, table_kw = (), {} |