]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Documented synonym_for and comparable_using in the main docstring for declarative...
authorMichael Trier <mtrier@gmail.com>
Sun, 5 Oct 2008 03:51:48 +0000 (03:51 +0000)
committerMichael Trier <mtrier@gmail.com>
Sun, 5 Oct 2008 03:51:48 +0000 (03:51 +0000)
lib/sqlalchemy/ext/declarative.py

index ad86360808107ea901cad436775c486dcbd25445..b7ae47edf99d26270770a1a3ef2582a69b1f0ef5 100644 (file)
@@ -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::