Hey,
Does Django hit the database again when making queries following relationships backwards using the FOO_set manager? I thought I read somewhere that it does not but I can't find it in the docs anywhere.
J
Hey,
Does Django hit the database again when making queries following relationships backwards using the FOO_set manager? I thought I read somewhere that it does not but I can't find it in the docs anywhere.
J
Yes, it does.
See my blog for a discussion of this issue and one possible way of optimising it.
You could always install the Django debug toolbar and see exactly how many hits a request generates: http://github.com/robhudson/django-debug-toolbar
Anyway, to answer your question, of course the database makes queries when it follows relationships; it has to get the data from somewhere. Like all querysets, however, it only actually hits the database when you request the first concrete row of data.