On Oct 3, 10:44 pm, Carl Meyer <c...@oddbird.net> wrote: > Hi Luke, > > On Oct 3, 9:04 am, Luke Plant <l.plant...@cantab.net> wrote: > > > The patch for this is now ready, as far as I'm concerned, but I'd like > > to bring it up here again before committing, mainly because Alex Gaynor > > expressed some doubts. > > > The latest patch is on the ticket: > > >https://code.djangoproject.com/ticket/16937 > > I know I'm a bit late to the party here (had a work deadline last > Friday). I think this functionality is valuable and makes sense to > have in the ORM, thanks for all the work on it. Though I don't have > time to go through the patch in detail, it seems like its gotten > several pairs of eyes over it closely already. > > My only real concern is one I'm a bit surprised hasn't been raised > already: API and naming sanity. If I'm a new user coming to this API, > as far as I'm concerned "select_related" and "prefetch_related" may as > well be synonyms - they don't tell me anything useful about how the > functions differ. And even knowing the internal details, any > justification for the naming seems tortured at best: both methods use > selects, and both prefetch something that would otherwise have to be > fetched separately later.
One convincing reason for merging select_related and prefetch_related is that if you have a setup like: Author -> foreign key: favorite_book -> Book -> m2m: authors -> Author If you do Author.objects.prefetch_related('favorite_book__authors') without issuing .select_related you will currently run a query for each author to fetch his favorite book. Then the authors would be fetched in a single query using prefetch. This is of course not what the user wants. If the above prefetch_related call results in automatic select_related, it would be a good idea to have the method called .select_related. The only problem I can think of is that if you for some reason want to clear prefetch_related but not select_related you can't do that. But that is not too bad of a problem. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.