>
> for entity in db(db.table2.id > 0).select():
>
    retVal += entity.table1.name
>

No, web2py does not retrieve entity.table1.name when the first line above 
is executed. Rather, it does a separate select when the second line is 
executed. entity.table1 is a DAL Reference object -- when you access one of 
its attbibutes (i.e., the name of a field in the referenced table), it does 
a database select to get the associated value. So, there are no extra 
queries with the initial select, but if you run that for loop, you will get 
an extra query for each iteration. This is mentioned in the book section on 
recursive 
selects <http://web2py.com/books/default/chapter/29/06#Recursive-selects>, 
where it is recommended to use a join rather than doing recursive selects 
over a large number of records (on GAE you couldn't do a join, but you 
could use .belongs() to minimize the number of queries).

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to