What prevents you from using select_related with an explicit list of relations that you *do* want? That's more maintainable as it prevents overfetching when you add new relations. If it were up to me I'd remove the "select_related()-selects-all-relations-behaviour" - it's too implicit and can lead to massive queries without much thought.
In many situations prefetch_related() outperforms select_related() as it doesn't pull back repeat copies of low-cardinality related objects. I covered this a bit in my N+1 blog post here: https://adamj.eu/tech/2020/09/01/django-and-the-n-plus-one-queries-problem/ . I'd also point you to django-auto-prefetch which performs prefetches across a queryset's objects on first access, eliminating nearly 90%+ of the need to manually tune select or prefetch_related calls. That's also covered in the blog post. On Thu, 3 Dec 2020 at 10:24, Roger Gammans <rgamm...@gammascience.co.uk> wrote: > Hi > > A recent question on one of the other django mailing lists reminded me of > this: I have a very edge (and almost certainly off the end of 'supported') > use case, where I would like to mark some relations on a model, as having > select_related() disabled. > > More specifically the requirement is that qs.select_related() (with no > args) doesn't include the marked relations. It doesn't look like there is a > way of doing this in the ORM as it stands - is this correct? > > I could probably work up this feature as a field flag, but given that it's > completely niche, I wondered what the chance of the core team accepting it > was. (with unittests)? > > > -- > > Roger Gammans <rgamm...@gammascience.co.uk> > Gamma Science Ltd. (GB Nr. 07356014 ) > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/0d9b15f264065bf090e7413e80f27d022d21a227.camel%40gammascience.co.uk > <https://groups.google.com/d/msgid/django-developers/0d9b15f264065bf090e7413e80f27d022d21a227.camel%40gammascience.co.uk?utm_medium=email&utm_source=footer> > . > -- Adam -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM3bJz-QB79LTjsXUJo7_K5PEopvYSAy9j1YE%3DvETTn9rQ%40mail.gmail.com.