#34413 closed New feature (duplicate)
Variant of Prefetch but for the earliest/latest related object — at Version 4
| Reported by: | Willem Van Onsem | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
What would happen if we span over multiple relations, like:
User.objects.prefetch_related(
Prefetch("groups__permissions", queryset=Permission.objects.order_by('codename')[:1], to_attr="first_permission")
)
Change History (5)
by , 3 years ago
| Attachment: | prefetching_the_earliest_latest_related_object_.patch added |
|---|
comment:1 by , 3 years ago
| Needs tests: | set |
|---|
comment:2 by , 3 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 3 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | assigned → closed |
comment:4 by , 3 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
Pretty sure this is a duplicate of #26780 fixed in the soon to be released 4.2.
Since 242499f2dc2bf24a9a5c855690a2e13d3303581a
Prefetch(queryset)supports slicing through the use of filtering over partitioned rank (RANK() OVER (PARTITION BY <join_field> ORDER BY <order_by>) so earliest and latest related objects (or any slice of related objects for that matter) can be prefetched.