diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-03-18 00:25:55 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-03-18 00:25:55 +0000 |
commit | c462e42dfd705ed781c9ae0505c0c65a71c8936e (patch) | |
tree | 8301c312b765816efa8d6d9c16c182a5e188ffc9 /lib/sqlalchemy/ext/declarative.py | |
parent | ad4e42567605e31b820766329f460a38603e05d1 (diff) | |
download | sqlalchemy-c462e42dfd705ed781c9ae0505c0c65a71c8936e.tar.gz |
- Declarative will complete setup for Columns lacking names, allows
a more DRY syntax.
class Foo(Base):
__tablename__ = 'foos'
id = Column(Integer, primary_key=True)
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 43cdad1cc..333b1eaa4 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -157,7 +157,7 @@ class DeclarativeMeta(type): return type.__init__(cls, classname, bases, dict_) cls._decl_class_registry[classname] = cls - our_stuff = {} + our_stuff = util.OrderedDict() for k in dict_: value = dict_[k] if (isinstance(value, tuple) and len(value) == 1 and @@ -180,9 +180,17 @@ class DeclarativeMeta(type): table_kw = {'autoload': True} else: table_kw = {} - cls.__table__ = table = Table(tablename, cls.metadata, *[ - c for c in our_stuff.values() if isinstance(c, Column) - ], **table_kw) + cols = [] + for key, c in our_stuff.iteritems(): + if not isinstance(c, Column): + continue + if c.key is None: + c.key = key + if c.name is None: + c.name = key + cols.append(c) + cls.__table__ = table = Table(tablename, cls.metadata, + *cols, **table_kw) else: table = cls.__table__ |