Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A few small cleanups in the join api and a test case for switching in

annotate -- hope to clean this up as well
  • Loading branch information...
commit 3aa06e8916d1f6053cdc786658fed2fd4a55461b 1 parent dcf37e2
Charles Leifer authored
Showing with 9 additions and 3 deletions.
  1. +3 −3 peewee.py
  2. +6 −0 tests.py
6 peewee.py
View
@@ -745,12 +745,12 @@ def _traverse(curr):
from_model = curr
to_model = join.model_class
- field = from_model._meta.rel_for_model(to_model, join.column)
+ field = from_model._meta.rel_for_model(to_model, join.on)
if field:
left_field = field.db_column
right_field = to_model._meta.primary_key.db_column
else:
- field = to_model._meta.rel_for_model(from_model, join.column)
+ field = to_model._meta.rel_for_model(from_model, join.on)
left_field = from_model._meta.primary_key.db_column
right_field = field.db_column
@@ -1087,7 +1087,7 @@ def inner(self, *args, **kwargs):
return inner
-Join = namedtuple('Join', ('model_class', 'join_type', 'column'))
+Join = namedtuple('Join', ('model_class', 'join_type', 'on'))
class Query(object):
require_commit = True
6 tests.py
View
@@ -586,6 +586,12 @@ def test_annotate(self):
self.assertSelect(sq, 'users."id", users."username", Count(blog."pk") AS count', [])
self.assertOrderBy(sq, 'count DESC', [])
+ sq = User.select().join(Blog, JOIN_LEFT_OUTER).switch(User).annotate(Blog)
+ self.assertSelect(sq, 'users."id", users."username", Count(blog."pk") AS count', [])
+ self.assertJoins(sq, ['LEFT OUTER JOIN "blog" AS blog ON users."id" = blog."user_id"'])
+ self.assertWhere(sq, '', [])
+ self.assertGroupBy(sq, 'users."id", users."username"', [])
+
def test_aggregate(self):
sq = User.select().where(User.id < 10)._aggregate()
self.assertSelect(sq, 'Count(users."id")', [])
Please sign in to comment.
Something went wrong with that request. Please try again.