Changes between Initial Version and Version 6 of Ticket #19195


Ignore:
Timestamp:
02/13/2014 12:01:11 AM (19 months ago)
Author:
charettes
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 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"
    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