From: Mike Bayer Date: Wed, 17 Sep 2008 19:31:24 +0000 (+0000) Subject: - Added label() method to InstrumentedAttribute X-Git-Tag: rel_0_4_8~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51d623d4692616536e9879ddd9c1145cab210aeb;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added label() method to InstrumentedAttribute to establish forwards compatibility with 0.5. --- diff --git a/CHANGES b/CHANGES index d84aaff7d8..206d2cb5fa 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ CHANGES SessionExtension.before_flush() will take effect for that flush. + - Added label() method to InstrumentedAttribute + to establish forwards compatibility with 0.5. + - sql - column.in_(someselect) can now be used as a columns-clause expression without the subquery diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index fb0621a70f..331ba36594 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -52,6 +52,9 @@ class InstrumentedAttribute(interfaces.PropComparator): def expression_element(self): return self.comparator.expression_element() + def label(self, name): + return self.clause_element().label(name) + def operate(self, op, *other, **kwargs): return op(self.comparator, *other, **kwargs) diff --git a/test/orm/query.py b/test/orm/query.py index 87af4063c5..dad3b95d22 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -249,6 +249,9 @@ class OperatorTest(QueryTest): def test_op(self): assert str(User.name.op('ilike')('17').compile(dialect=default.DefaultDialect())) == "users.name ilike :name_1" + def test_label(self): + assert str(User.name.label('foobar').compile() == "users.name AS foobar") + def test_in(self): self._test(User.id.in_(['a', 'b']), "users.id IN (:id_1, :id_2)") @@ -1132,7 +1135,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): sess.clear() self.assertRaises(exceptions.InvalidRequestError, sess.query(User).add_column, object()) - + def test_ambiguous_column(self): sess = create_session()