Thanks for your suggestion...it pointed me in the right direction. It turns out the issue is not with the query construction, but that DAL handles string input differently to objects. What I am trying to do is take a Query and then convert it to a string so it can be saved in the session. The string can then be pulled from the session and converted back into a Query. This works for simple queries, but not for queries with implicit joins. See the difference:
>>>from gluon.dal import Query >>>query = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & >>>(db.comment.page_id == db.webpage.id) >>>query_as_string = str(query) >>>query_from_string = Query(db, query_as_string) >>>db(query)._select(db.comment.body) "SELECT comment.body FROM comment, webpage WHERE (((comment.id > 0) AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));" >>>db(query_from_string)._select(db.comment.body) "SELECT comment.body FROM comment WHERE ((((comment.id > 0) AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));" Does anyone know how to convert a Query to a string (so it can be saved in the session) and then get it back again? On Mar 24, 4:52 am, Wikus van de Merwe <dupakrop...@googlemail.com> wrote: > Just a blind guess but does this work any better? > query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id == > webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id == > comment_tags.tag_id) & (tag.label == 'Agree') > db(query).select()