Changes between Initial Version and Version 6 of Ticket #19195


Ignore:
Timestamp:
Feb 13, 2014, 12:01:11 AM (11 years ago)
Author:
Simon Charette
Comment:

Just hit this issue and had a hard time figuring out what I've done wrong.

Intuitively I tried .distinct('related_id').order_by('related_id') after realizing removing my Related._meta.ordering solved the issue but, as pointed out by akaariai, this is not allowed ATM.

Replying to akaariai:

I think we should allow using .order_by('team_id') here.

Related fields have two attributes on model level - team and team_id in this case. We allow using team_id in many places in the ORM already, and to me it seems we should allow it in order_by and distinct, too.

Is there some reason to *not* allow them?

I can't think of any reason we'd like *not* to allow them. It looks like sanest to expose an API to explicitly opt-out of the existing related model ordering behavior while maintaining backward compatibility.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19195

    • Property Triage Stage UnreviewedAccepted
    • Property Cc Simon Charette added
  • Ticket #19195 – Description

    initial v6  
    11I tried to using a distinct filter like this: Appearance.objects.order_by('team').distinct('team'); this fails with the following Database Error: "DatabaseError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions"
    22
    3 It is possible to work around this problem by using this modified filter: Appearance.objects.order_by('team__id').distinct('team__id').
     3It is possible to work around this problem by using this modified filter: `Appearance.objects.order_by('team__id').distinct('team__id')`.
    44
    55Model definition: http://pastebin.com/index/J45fy9fr
Back to Top