Skip to content
This repository
Browse code

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 October 09, 2012

Showing 2 changed files with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. 6  peewee.py
  2. 6  tests.py
6  peewee.py
@@ -745,12 +745,12 @@ def _traverse(curr):
745 745
                 from_model = curr
746 746
                 to_model = join.model_class
747 747
 
748  
-                field = from_model._meta.rel_for_model(to_model, join.column)
  748
+                field = from_model._meta.rel_for_model(to_model, join.on)
749 749
                 if field:
750 750
                     left_field = field.db_column
751 751
                     right_field = to_model._meta.primary_key.db_column
752 752
                 else:
753  
-                    field = to_model._meta.rel_for_model(from_model, join.column)
  753
+                    field = to_model._meta.rel_for_model(from_model, join.on)
754 754
                     left_field = from_model._meta.primary_key.db_column
755 755
                     right_field = field.db_column
756 756
 
@@ -1087,7 +1087,7 @@ def inner(self, *args, **kwargs):
1087 1087
     return inner
1088 1088
 
1089 1089
 
1090  
-Join = namedtuple('Join', ('model_class', 'join_type', 'column'))
  1090
+Join = namedtuple('Join', ('model_class', 'join_type', 'on'))
1091 1091
 
1092 1092
 class Query(object):
1093 1093
     require_commit = True
6  tests.py
@@ -586,6 +586,12 @@ def test_annotate(self):
586 586
         self.assertSelect(sq, 'users."id", users."username", Count(blog."pk") AS count', [])
587 587
         self.assertOrderBy(sq, 'count DESC', [])
588 588
 
  589
+        sq = User.select().join(Blog, JOIN_LEFT_OUTER).switch(User).annotate(Blog)
  590
+        self.assertSelect(sq, 'users."id", users."username", Count(blog."pk") AS count', [])
  591
+        self.assertJoins(sq, ['LEFT OUTER JOIN "blog" AS blog ON users."id" = blog."user_id"'])
  592
+        self.assertWhere(sq, '', [])
  593
+        self.assertGroupBy(sq, 'users."id", users."username"', [])
  594
+
589 595
     def test_aggregate(self):
590 596
         sq = User.select().where(User.id < 10)._aggregate()
591 597
         self.assertSelect(sq, 'Count(users."id")', [])

0 notes on commit 3aa06e8

Please sign in to comment.
Something went wrong with that request. Please try again.