From 9e3d161d0d7ecb11dd7c9c057a60d7eb3231fd44 Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Sun, 5 Oct 2008 03:51:48 +0000 Subject: [PATCH] Documented synonym_for and comparable_using in the main docstring for declarative. Fixes #1144. --- lib/sqlalchemy/ext/declarative.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index ad86360808..b7ae47edf9 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:: -- 2.47.3