#20923: Unable to use fields from prefetch_related() in only() and defer() -------------------------------------+------------------------------------- Reporter: alexpirine | Owner: nobody Type: New feature | Status: closed Component: Database layer | Version: 1.5 (models, ORM) | Resolution: wontfix Severity: Normal | Triage Stage: Keywords: defer only | Unreviewed ForeignKey reverse relationship | Needs documentation: 0 Has patch: 0 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by alexpirine): Replying to [comment:3 akaariai]: > I think a better way is to add custom query support to prefetch_related (or, #17001). Main reason is that I believe implementation of communicating the only/defer data from the main query to the prefetch queries will be hard to do cleanly. Thanks, it looks interesting. If I understood it correctly, I could pass the only() attribute to the custom queryset: {{{ ParentModel.objects.prefetch_related( R('child_model', to_attr = 'childs', qs = ChildModel.objects.only('child_attribute') ).only('parent_attribute').all() }}} which would answer this issue. -- Ticket URL: <https://code.djangoproject.com/ticket/20923#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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.f005a5fc450f0f20108fba835e16b6fe%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.