diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-04 13:48:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-04 13:48:46 -0500 |
commit | e46301b5154000148155ef00d15b35857ebb31ad (patch) | |
tree | 2b34b20e2ac178827a9b907b95559efee5fddfb1 /lib/sqlalchemy/ext/declarative.py | |
parent | 8f78d5ba00f7e8656bdd7fd07dbadb5a6b4d1b72 (diff) | |
download | sqlalchemy-e46301b5154000148155ef00d15b35857ebb31ad.tar.gz |
- The Index() construct can be created inline with a Table
definition, using strings as column names, as an alternative
to the creation of the index outside of the Table.
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 39aaf5488..898a9a728 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -819,7 +819,7 @@ from multiple collections:: __tablename__='my_model' @declared_attr - def __table_args__(self): + def __table_args__(cls): args = dict() args.update(MySQLSettings.__table_args__) args.update(MyOtherMixin.__table_args__) @@ -827,6 +827,25 @@ from multiple collections:: id = Column(Integer, primary_key=True) +Creating Indexes with Mixins +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To define a named, potentially multicolumn :class:`.Index` that applies to all +tables derived from a mixin, use the "inline" form of :class:`.Index` and establish +it as part of ``__table_args__``:: + + class MyMixin(object): + a = Column(Integer) + b = Column(Integer) + + @declared_attr + def __table_args__(cls): + return (Index('test_idx_%s' % cls.__tablename__, 'a', 'b'),) + + class MyModel(Base,MyMixin): + __tablename__ = 'atable' + c = Column(Integer,primary_key=True) + Class Constructor ================= |