It doesn't. I found this: """" GAE does not support belongs and does not support OR. You have to do:
rows = db(db.media_type.name=='paper').select()&db (db.media_type.name=='cd').select() The & is done at the web2py level but since records are exclusive and you are not sorting them, there is no major slowdown. """"" Since I'm a python newbie, how would you go about building the loop that creates a very long query? you need to do some kind of python eval tricks here that I don't know. I'm guessing its going to look like for id in board_ids: query = query + new query(id) but how do you do it in python? On Wednesday, March 21, 2012 8:30:54 PM UTC-4, Anthony wrote: > > I didn't realize you were on GAE. I'm not quite sure how GAE handles this, > so perhaps someone with more GAE experience can chime in. In an RDBMS, you > should be able to do: > > board_ids = set([a.board for a in articles]) > boards = db(db.boards.id.belongs(board_ids)).select() > > But not sure if that works on GAE. > > Anthony > > On Wednesday, March 21, 2012 7:30:58 PM UTC-4, Udi Milo wrote: >> >> Anthony, >> >> Thanks for answering so quickly. >> I did mean board and not board_id >> >> My question is very basic. >> I know that the article table has an Id column that is really the board >> reference, but when I look at the result of the query and unification of: >> board_ids = set(map(lambda a: a.board, articles)) >> >> I get a set of references, >> how do I use that set in another query to get all the boards? >> also, just to be sure, running this lambda expression does not hit the db >> to fetch the boards, right? >> >> I can't use join b/c I'm running on GAE. >> >> >> >> On Wednesday, March 21, 2012 5:22:50 PM UTC-4, Anthony wrote: >>> >>> I have two db tables: >>>> >>>> board (name, created_on) >>>> article(board, name, title) >>>> >>>> currently, in my html I do a naive loop {{for article in articles}} {{= >>>> article.board.name}} {{pass}} >>>> >>>> I would like to change it and do something like: >>>> articles = db.select.all....... >>>> board_ids = set(map(lambda a: a.board_id, articles)) >>>> >>> >>> Instead of a.board_id, do you mean a.board (I don't see a "board_id" >>> field listed in your article table definition)? Also, is db.article.board a >>> reference field to the db.board table? In that case, that means it is >>> already storing the id of the referenced record in the db.board table >>> (that's what reference fields store), so you don't need to retrieve it >>> separately. >>> >>> Anyway, if you need the db.board.name value for all the records you are >>> selecting from the db.article table, you should probably just do a join so >>> you can get everything in a single query -- see >>> http://web2py.com/books/default/chapter/29/6#Inner-joins. >>> >>> Anthony >>> >>>