No. This should not produce double results: results = db(q1 & q2).select()
Unless results are duplicated in database. On Saturday, 28 June 2014 07:00:27 UTC-5, Riccardo C wrote: > > Hi Massimo, > > thanks for taking time to have a look to my problem. > Regarding the first suggestion, what I was trying to do was exactly what > you corrected. > > The query itself doesn't work as I would: in plain english, I would like > to have a complete list of users that live in a specific city AND know a > specific language. > > By doing what you suggested I get doubles row (as the search was done > separately and independently on the two tables and the results then > presented together), eg. I get user1 because it lives in London and I get > user1 because he speaks Italian, but I get also user2 because it leaves in > London BUT only one because it doesn't speak italian. It is what I should > expect? > > Thanks > > Riccardo > > On Friday, 27 June 2014 06:53:57 UTC+1, Massimo Di Pierro wrote: >> >> This is very wrong: >> >> q1 = eval('db. userLanguage.'+ language )== True >> >> what is it supposed to be? >> >> >> q1 = db.userLanguage[language] == True >> >> I am not sure. Once q1 is correct, this works: >> >> results = db(q1 & q2).select() >> >> On Wednesday, 25 June 2014 17:04:28 UTC-5, Riccardo C wrote: >>> >>> Dear all, >>> >>> I am trying to formulate a query to get ALL the people that know a >>> language AND leave in a specific city. >>> As I am not an expert I thought that was a good idea to have two tables >>> as following: >>> auth.settings.extra_fields['auth_user']= [ >>> Field('city',requires=IS_IN_SET(('UK - London','IT - Milano','USA - New >>> York')) )] >>> >>> >>> db.define_table('userLanguage', >>> Field('idUser','reference auth_user', unique=True), >>> Field('French','boolean',default = False), >>> Field('Italian','boolean',default = False), >>> Field('Chinese','boolean',default = False), >>> Field('Indian','boolean',default = False)) >>> >>> in term of controller search function I decided to get the information >>> from the URL (that in my idea will be generate from a javascript function >>> depending of what the user select on the page): >>> def search(): >>> >>> lstLanguages = ['French', 'Italian', 'Chinese', 'Indian'] >>> >>> lstCity = ['UK - London','IT - Milano','USA - New York'] >>> >>> language = lstLanguages[int(request.vars.n)] >>> userCity = lstCity[int(request.vars.c)] >>> >>> q1 = eval('db. userLanguage.'+ language )== True >>> q2 = db.auth_user.city == userCity >>> >>> """ QUERY: give me the list of users that know that language and >>> live in that city""" >>> >>> >>> return dict(form = chefResults) >>> >>> As written above I tried different way to do that (without succed): >>> >>> results = db(q1 & q2).select() """ gives me, as expected the sum of the >>> two query results""" >>> ------------------------------- >>> results2 = db(q1).select() '''this return those who speak the selected >>> language''' >>> searchresults = [row for row in results2 if results2.idUser_city == >>> userCity] '''this make web2py to crash! I have to kill the process...why?''' >>> >>> I hope to not have bother you too much, I would like to learn and >>> understand... in particular: >>> 1) which is the best way of doing this kind of query? >>> 2) is there a better way of structuring the data (db tables) >>> 3).... why it crashes?! >>> 4) what would be the best way to pass the search criteria to the >>> function? >>> >>> Thanks for any answer and I hope it might be useful for other people as >>> well. >>> >>> Regards, >>> >>> Riccardo >>> >>> >>> >>> -- 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.