diff options
| author | Michael Trier <mtrier@gmail.com> | 2008-10-05 03:51:48 +0000 |
|---|---|---|
| committer | Michael Trier <mtrier@gmail.com> | 2008-10-05 03:51:48 +0000 |
| commit | 9e3d161d0d7ecb11dd7c9c057a60d7eb3231fd44 (patch) | |
| tree | ee10b00d431bf0755024322ea4c1c8741f099bf3 /lib/sqlalchemy/ext | |
| parent | f0a40280fd2efa2708d1cd09ca074779aa76649e (diff) | |
| download | sqlalchemy-9e3d161d0d7ecb11dd7c9c057a60d7eb3231fd44.tar.gz | |
Documented synonym_for and comparable_using in the main docstring for declarative. Fixes #1144.
Diffstat (limited to 'lib/sqlalchemy/ext')
| -rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index ad8636080..b7ae47edf 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -136,6 +136,30 @@ class-level expression construct:: x.attr = "some value" session.query(MyClass).filter(MyClass.attr == 'some other value').all() +The `synonym_for` decorator can accomplish the same task:: + + class MyClass(Base): + __tablename__ = 'sometable' + + _attr = Column('attr', String) + + @synonym_for('_attr') + @property + def attr(self): + return self._some_attr + +Similarly, `comparable_using` is a front end for the `comparable_property` ORM function:: + + class MyClass(Base): + __tablename__ = 'sometable' + + name = Column('name', String) + + @comparable_using(MyUpperCaseComparator) + @property + def uc_name(self): + return self.name.upper() + As an alternative to ``__tablename__``, a direct ``Table`` construct may be used. The ``Column`` objects, which in this case require their names, will be added to the mapping just like a regular mapping to a table:: |
