Hum, I forgot the problem has two tables. Nice!
2013/6/4 Massimo Di Pierro <massimo.dipie...@gmail.com> > I would replace > > retVal = [] > for entity in db(db.table2.id > 0).select(): > retVal += entity.table1.name > > with > > table1_map = db(db.table2 <http://db.table2.id/>).select().as_dict() > retVal = [table1_map[entity.table1].name <http://entity.table1.name/> for > entity in db(db.table2 <http://db.table2.id/>).select()] > > It will loads all records from table1 in ram but your code does it too. > Two queries instead of many. > select().as_dict() creates a dict where the key is the id and the value is > the record. > > On Tuesday, 4 June 2013 04:25:06 UTC-5, guruyaya wrote: >> >> Lets examine this code for a sec: >> db.define_table('table1',**Field('name')) >> db.define_table('table2',**Field('table1', db.table1), Field('name2')) >> >> Now, if I need a list of all table2 entries, but not the table1 entries, >> I'll do something like this: >> >> retVal = [] >> for entity in db(db.table2.id > 0).select(): >> retVal += entity.name2 >> >> BUT >> As you well know, web2py acctuall did ask for table1 info, just in case >> I'll do this: >> >> retVal = [] >> for entity in db(db.table2.id > 0).select(): >> retVal += entity.table1.name >> >> On a normal hosting, it doesn't matter that much, but on GAE, it does an >> extra query to the datastore, and that's just a waste. >> Is there a way to avoid that? >> >> Thanks in advance >> Yair >> > -- > > --- > 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. > > > -- Att. Carlos J. Costa Cientista da Computação Esp. Gestão em Telecom EL MELECH NEEMAN! אָמֵן -- --- 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.