Commits

Michael Manfre committed 0b78d5d

bug 66 - Slicing without specifying an order fails when pk's attname doesn't match db_column.

Comments (0)

Files changed (2)

source/sqlserver_ado/query.py

             if order is None:
                 meta = self.get_meta()
                 qn = self.connection.ops.quote_name
-                order = '%s.%s ASC' % (qn(meta.db_table), qn(meta.pk.attname))
+                column = meta.pk.db_column or meta.pk.get_attname()
+                order = '%s.%s ASC' % (qn(meta.db_table), qn(column))
             
             where_row_num = "%s < _row_num" % (self.low_mark)
             if self.high_mark:

tests/test_main/regressiontests/models.py

     """
 
     a = models.IntegerField()
-    
+
 class Bug62Table(models.Model):
     email = models.CharField(max_length=255, blank=True)
 
     True
     """
     
-    key = BigForeignKey(Bug63Table)
+    key = BigForeignKey(Bug63Table)
+
+
+class Bug66Table(models.Model):
+    """
+    Test that pagination works when pk uses db_column
+
+    >>> Bug66Table(a=100).save()
+    >>> Bug66Table(a=101).save()
+    >>> Bug66Table(a=102).save()
+    >>> len(list(Bug66Table.objects.all()))
+    3
+
+    >>> objs = Bug66Table.objects.all()
+    >>> all_objs = Paginator(objs, 1)
+    >>> all_objs.count
+    3
+    >>> all_objs.num_pages
+    3
+    >>> page1 = all_objs.page(1)
+    >>> page1.object_list[0].a
+    100
+    >>> page2 = all_objs.page(2)
+    >>> page2.object_list[0].a
+    101
+    """
+    id = models.AutoField(primary_key=True, db_column='bug41id')
+    a = models.IntegerField()
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.