#24218: Use sub-query in ORM when distinct and order_by columns do not match
-------------------------------------+-------------------------------------
Reporter: miki725 | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: subquery distinct | Triage Stage: Accepted
order_by |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by akaariai):
We need to go wirh option 2, specifically the solution where the inner and
outer query have differen order by clauses. This way you can order the
results the way you want, yet pick the distinct element as you wish.
I'vw thought of a solution something like this
{{{
qs.distict('foo').order_by('foo').barrier().order_by('bar')
}}}
The idea is that the barrier call effectively forces everything left of
the call to go into subquery, then things after the barrier go into outer
query. This construct would be hugely useful in other use cases, too.
--
Ticket URL: <https://code.djangoproject.com/ticket/24218#comment:7>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.29bab7d17ea7c26170d6a10a7575ed33%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.