#15108: order_by on annotate doesn't work with camelCased annotation names
---------------------------------------------------+------------------------
Reporter: jorn | Owner: nobody
Status: closed | Milestone:
Component: Database layer (models, ORM) | Version: 1.2
Resolution: worksforme | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by kmtracey):
* status: new => closed
* needs_better_patch: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_docs: => 0
Comment:
There is something beyond what is mentioned here going on. Is it not as
simple as camel case in annotation names. Taking contrib models Group and
Permission that have the same !ManyToMany relationship as your Game and
User:
{{{
>>> from django.db import connection
>>> from django.db.models import Count
>>> from django.contrib.auth.models import Permission
>>> x =
list(Permission.objects.annotate(groupcount=Count('group')).order_by('-groupcount'))
>>> connection.queries[-1]
{'time': '0.003', 'sql': u'SELECT `auth_permission`.`id`,
`auth_permission`.`name`, `auth_permission`.`content_type_id`,
`auth_permission`.`codename`, COUNT(`auth_group_permissions`.`group_id`)
AS `groupcount` FROM `auth_permission` LEFT OU
TER JOIN `auth_group_permissions` ON (`auth_permission`.`id` =
`auth_group_permissions`.`permission_id`) GROUP BY `auth_
permission`.`id`, `auth_permission`.`id`, `auth_permission`.`name`,
`auth_permission`.`content_type_id`, `auth_permissio
n`.`codename` ORDER BY groupcount DESC'}
>>> x =
list(Permission.objects.annotate(groupCount=Count('group')).order_by('-groupCount'))
>>> connection.queries[-1]
{'time': '0.001', 'sql': u'SELECT `auth_permission`.`id`,
`auth_permission`.`name`, `auth_permission`.`content_type_id`,
`auth_permission`.`codename`, COUNT(`auth_group_permissions`.`group_id`)
AS `groupCount` FROM `auth_permission` LEFT OU
TER JOIN `auth_group_permissions` ON (`auth_permission`.`id` =
`auth_group_permissions`.`permission_id`) GROUP BY `auth_
permission`.`id`, `auth_permission`.`id`, `auth_permission`.`name`,
`auth_permission`.`content_type_id`, `auth_permissio
n`.`codename` ORDER BY groupCount DESC'}
>>>
}}}
Tried on both the reported version (1.2) and trunk. You might find further
clues by taking a look at the full SQL query that is being executed for
the query. If you can give some more clues as to what else is coming into
play here feel free to re-open the ticket, but with the information
provided so far I cannot recreate so am closing worksforme for now.
--
Ticket URL: <http://code.djangoproject.com/ticket/15108#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.