Reputation: 2140
Let's say you have this code:
products = session.query(Products)
query = products.filter(Products.productVendor == 'Classic Metal Creations')
for q in query:
print q
When is the database queried? How many times is the database queried here?
So for example. when we do a filter()
on products
, are we just performing that operation client-side on the result set that we got from the original query?
Upvotes: 0
Views: 28
Reputation: 20538
The database is actually queried when you iterate through query
, i.e. the line for q in query
. This includes calling all()
, first()
, scalar()
, etc. on the query. filter()
only generatively modifies the query to include the filter.
Upvotes: 1