Let's say I query Workplaces in a City and prefetch all their Workers, which is a many-to-many relationship:
workplaces = list(city.workerplace_set.filter(num_employees__lte=350).prefetch_related('Worker'))
If I use any QuerySet operation on Workers from any of the Workplaces, will the database be hit or not? I could not make out a clear answer from the docs.
workplaces_with_interns = [workplace for workplace in workplaces
# is this filter going to query the database?
if workplace.worker_set.filter(salary=0).exists()]
PS: someone is probably going to point out that I can reach the same answer by simply making a query for city.workerplace_set instead of making it a list. Yes, I know, but that is not possible because I am caching the workplaces so that the database is not hit every time the function that does all this is called.