#26195: order_by pk doesn't work in multi-table inheritance models if parent has
default ordering
-------------------------------------+-------------------------------------
Reporter: ris | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: multi table | Triage Stage:
inheritance order_by MTI pk | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by charettes):
Replying to [comment:4 ris]:
>I've now found cases where specifying a related model to `.order_by()`
will cause this behaviour whereas simply adding `__pk` to that model
lookup will allow it to work fine.
Again, this is just like documented.
{{{#!python
class Author(models.Model):
name = models.CharField(max_length=100)
class Meta:
ordering = ['name']
class Book(models.Model):
author = models.ForeignKey(Author)
# Equivalent to order_by('author__name')
Book.objects.order_by('author')
# Equivalent of order_by('author__id'), it bypasses the defined ordering
but results in a JOIN.
Book.objects.order_by('author__pk')
# Used to be equivalent of order_by('author__name') before #19195 was
fixed.
Book.objects.order_by('author_id')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26195#comment:5>
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/061.da7efa458502d0cf0113336e49b3391b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.