From: Mike Bayer Date: Tue, 6 May 2008 00:55:49 +0000 (+0000) Subject: - _Label adds itself to the proxy collection so that it works in correspoinding colum... X-Git-Tag: rel_0_5beta1~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=538861143f66e7299f60b42a505242edd6351908;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - _Label adds itself to the proxy collection so that it works in correspoinding column. fixes some eager load with column_property bugs. - this partially fixes some issues in [ticket:1022] but leaving the "unlabeled" fix for 0.5 for now --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 269d31661e..867fdd69c3 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1733,7 +1733,10 @@ class FromClause(Selectable): col, intersect = None, None target_set = column.proxy_set - for c in self.c + [self.oid_column]: + cols = self.c + if self.oid_column: + cols += [self.oid_column] + for c in cols: i = c.proxy_set.intersection(target_set) if i and \ (not require_embedded or c.proxy_set.issuperset(target_set)) and \ @@ -2553,9 +2556,11 @@ class _Label(ColumnElement): def _make_proxy(self, selectable, name = None): if isinstance(self.obj, (Selectable, ColumnElement)): - return self.obj._make_proxy(selectable, name=self.name) + e = self.obj._make_proxy(selectable, name=self.name) else: - return column(self.name)._make_proxy(selectable=selectable) + e = column(self.name)._make_proxy(selectable=selectable) + e.proxies.append(self) + return e class _ColumnClause(ColumnElement): """Represents a generic column expression from any textual string. diff --git a/test/orm/eager_relations.py b/test/orm/eager_relations.py index 866eec718e..418df83dda 100644 --- a/test/orm/eager_relations.py +++ b/test/orm/eager_relations.py @@ -1047,14 +1047,16 @@ class SubqueryTest(ORMTest): self.assertEquals(user.query_score, user.prop_score) self.assert_sql_count(testing.db, go, 1) - u = session.query(User).filter_by(name='joe').one() - self.assertEquals(u.query_score, u.prop_score) - - # fails: - #def go(): - # u = session.query(User).filter_by(name='joe').one() - # self.assertEquals(u.query_score, u.prop_score) - #self.assert_sql_count(testing.db, go, 1) + + # fails for non labeled (fixed in 0.5): + if labeled: + def go(): + u = session.query(User).filter_by(name='joe').one() + self.assertEquals(u.query_score, u.prop_score) + self.assert_sql_count(testing.db, go, 1) + else: + u = session.query(User).filter_by(name='joe').one() + self.assertEquals(u.query_score, u.prop_score) for t in (tags_table, users_table): t.delete().execute() diff --git a/test/sql/selectable.py b/test/sql/selectable.py index d3b6397674..b29ba8d5c0 100755 --- a/test/sql/selectable.py +++ b/test/sql/selectable.py @@ -174,6 +174,15 @@ class SelectableTest(TestBase, AssertsExecutionResults): print str(j) self.assert_(criterion.compare(j.onclause)) + def test_labeled_select_correspoinding(self): + l1 = select([func.max(table.c.col1)]).label('foo') + + s = select([l1]) + assert s.corresponding_column(l1).name == s.c.foo + + s = select([table.c.col1, l1]) + assert s.corresponding_column(l1).name == s.c.foo + def testselectaliaslabels(self): a = table2.select(use_labels=True).alias('a') print str(a.select())