On Thu, Jul 16, 2009 at 9:00 PM, Ilya Novoselov<ilya.novose...@gmail.com> wrote: > > I'm sorry if this have been discussed before. > > I have table A, which have foreign key foo to model B. > > When I query B related set trough B.a_set.all(). > When I iterate over b_instance.a_set.all() and access foo member, > Django doesn't hesitate to make database query to retrieve B again and > again. Sometimes I can override it setting foo = b_instance manually > and then calling methods on foo, but that's not always possible. > > Using a_set.selected_related('foo') is overkill for a database too. > > Any comments?
You are correct that this could be optimized. Truth be told, I'm a little surprised that this optimization isn't already happening - we optimize a number of lookup cases when foreign keys are involved, and I can't think of an obvious reason that we're not doing this optimization. This should be opened as a ticket in Django's Trac instance: http://code.djangoproject.com/simpleticket Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---