> db((db.task.id == 5) & (db.task.ref_to_job == db.job.id) & 
> (db.job.ref_to_project == db.project.id) & (db.project.owner == 
> auth.user_id))
>
> I tried it and it works, but I am not sure how different it is from the 
> one Leonel suggested. How does this work?
>

The above does a join, so it gets the data in a single database request, 
whereas Leonel's example involved a recursive select (behind the scenes, 
task.job.project.owner does two additional queries, beyond the query to get 
the tasks records).
 

> Also, you mentioned to check the timing of the query. Is there a web2py 
> way to do that?
>

See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Timing-queries.
 
Note, db._timings shows the actual SQL code, not your DAL code, so you'll 
have to figure out what DAL code generated what SQL. Leonel's code will 
generate three separate database requests with three separate timings that 
must be added together. Your join example above will generate only a single 
database request.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to