Opened 6 hours ago
Last modified 6 hours ago
#36644 new New feature
Enable using an empty order_by() to disable implicit primary key ordering in first()
Reported by: | Lily | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As discussed in https://github.com/django/new-features/issues/71, update the interaction between order_by
and first
to enable this behaviour:
# Existing MyModel.objects.first() # first, ordered by `pk` MyModel.objects.order_by("pk").first() # as above MyModel.objects.order_by("name").first() # first, ordered by `name` # New MyModel.objects.order_by().first() # first, but in whatever order the database returns it
This will interact with default orderings (`Meta.ordering`), which will need some careful handling.
Note:
See TracTickets
for help on using tickets.