Skip to content

Commit

Permalink
Allow inner query values to be used in outer query joins. Fixes #340
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Jul 12, 2014
1 parent 19c8a9b commit db69822
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,18 @@ def test_subselect_with_column(self):
query = outer.order_by(inner.c.name.desc())
self.assertEqual([u[0] for u in query.tuples()], ['u1', 'u0'])

def test_subselect_with_join(self):
inner = User.select(User.id, User.username).alias('q1')
outer = (Blog
.select(inner.c.id, inner.c.username)
.from_(inner)
.join(Comment, on=(inner.c.id == Comment.id)))
sql, params = compiler.generate_select(outer)
self.assertEqual(sql, (
'SELECT "q1"."id", "q1"."username" FROM ('
'SELECT users."id", users."username" FROM "users" AS users) AS q1 '
'INNER JOIN "comment" AS comment ON ("q1"."id" = comment."id")'))


class PrefetchTestCase(ModelTestCase):
requires = [User, Blog, Comment, Parent, Child, Orphan, ChildPet, OrphanPet, Category]
Expand Down

0 comments on commit db69822

Please sign in to comment.