Can you quickly explain the difference between: (db.clothing.id==db.clothing_person.clothing_Id) & (db.person.id==db.clothing_person.person_id)
and (db.clothing_person.clothing_id==db.clothing.id) & (db.clothing_person.person_id==db.person.id) On Wednesday, January 29, 2014 5:15:51 PM UTC-5, Niphlod wrote: > > You can't achieve it without a "custom function", but it's not that hard > to write.... > > //totally untested// > > def search_whatever(people=[], items=[], clothings=[]): > q = db.people.name.belongs(people) > if items: > q = q & (db.item_person.person_id == db.person.id) #the > reference > q = q & (db.item.name.belongs(items)) > if clothing: > q = q & ( > (db.clothing.id == db.clothing_person.clothing_id) & > (db.person.id == db.clothing_person.person_id) > ) #the reference > q = q & (db.clothing.name.belongs(clothings)) > ........ > rows = db(q).select(db.person.ALL) > return rows > > > > > > On Wednesday, January 29, 2014 11:03:06 PM UTC+1, Apple Mason wrote: >> >> Is there a more lenient version of what_I_want that will give me based on >> what I put in? For example, >> >> If I just want all people named Bob, it would return all people named Bob. >> >> If I just want all people named Bob or nicknamed Bobcat, then I wlll get >> all people named Bob or nicknamed Bobcat. >> >> If I just want all people nicknamed Bobcat who also have item1, item2, >> then I get all people nicknamed Bobcat with item1,item2 >> >> If I just want all people named Bob and nicknamed Bobcat and have item1, >> and clothing1, clothing2, then I get all people named Bob and nicknamed >> Bobcat with item1, clothing1, clothnig2 >> >> Right now if I do: >> >> what_i_want = ( >> (db.person.name=='Bob') & >> (db.item.name=='item1') & >> (db.clothing.name=='clothing1') >> ) >> >> I get results. But if I do: >> >> what_I_want = ( >> (db.person.name=='Bob') >> ) >> >> It doesn't return any rows. >> >> On Wednesday, January 29, 2014 3:14:09 AM UTC-5, Niphlod wrote: >>> >>> why the hassle of using joins like those ones ? >>> If you're not fond of searching through left joins, and you still want >>> your whole dataset "consistent", and a search "a-la-fulltext".....better do >>> something like this >>> >>> whole_set = ( >>> (db.person.id == db.clothing_person.person_id) & >>> (db.clothing.id == db.clothing_person.clothing_id) & >>> (db.item_person.person_id == db.person.id) & >>> (db.item_person.item_id == db.item.id) >>> ) >>> >>> then, you can search it as >>> >>> what_I_want = ( >>> (db.person.name == 'Bob') & >>> .... >>> (db.item.name == 'item1') >>> ) >>> >>> rows = db(whole_set)(what_I_want).select() >>> >>> On Wednesday, January 29, 2014 6:29:10 AM UTC+1, Apple Mason wrote: >>>> >>>> I want to search across some many to many tables, but with certain >>>> conditions. >>>> >>>> >>>> db.define_table('person', >>>> Field('name', 'string'), >>>> Field('nickname', 'string')) >>>> >>>> db.define_table('clothing', >>>> Field('name', 'string')) >>>> >>>> db.define_table('item', >>>> Field('name', 'string')) >>>> >>>> db.define_table('item_person', >>>> Field('person_id', 'reference person'), >>>> Field('item_id', 'reference item')) >>>> >>>> db.define_table('clothing_person', >>>> Field('person_id', 'reference person'), >>>> Field('clothing_id', 'reference clothing')) >>>> >>>> >>>> >>>> How would I find all people who have the name 'Bob' or nickname >>>> 'Bobcat' AND have items called 'item1' and 'item2' AND have clothing >>>> 'clothing1' ? >>>> >>>> For example, these are valid results: >>>> >>>> Bob has item1, item2 and clothing1 >>>> Bobcat has item1, item2 and clothing1 >>>> >>>> Would I use a join for this? Maybe something like: >>>> >>>> db( (db.person.name.like('Bob')) | >>>> (db.person.name.like('Bobcat')).select(db.person.ALL, join=[ >>>> db.item_person.on( >>>> (db.item.id==db.item_person.item_id) >>>> & ((db.item.name=='item1') & (db.item.name='item2'))), >>>> db.clothing_person.on( >>>> (db.clothing.id==db.clothing_person.clothing_id) >>>> & (db.clothing.name=='clothing1')) >>>> ]) >>>> >>>> But that doesn't seem correct. >>>> >>> -- 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/groups/opt_out.