Changes between Initial Version and Version 6 of Ticket #19195

02/13/2014 12:01:11 AM (15 months ago)

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.


  • Ticket #19195

    • Property Cc charettes added
    • Property Patch needs improvement unset
    • Property Needs tests unset
    • Property Needs documentation unset
    • Property Triage Stage changed from Unreviewed to Accepted
  • 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"
    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')`.
    55Model definition:
Back to Top