assuming that your filter is indeed 

myfilter = db(db.thefilter.name == 'Tops')


all_products_that_are_tops = db(db.products.thefilter.belongs(myfilter.
_select(db.thefilter.id)))

this basically searches all the ids of the "thefilter" table that have a 
"name" == Tops.
Then passes those id to the "products" table that holds a reference to the 
"thefilter" table.

Il giorno venerdì 10 maggio 2013 17:26:30 UTC+2, brac...@gmail.com ha 
scritto:
>
> How do I search for all products of a certain combination of filters in a 
> many to many relationship? The products returned have to at least have the 
> filters given.
>
> For example, if I had this many to many relationship:
>
> db.define_table('thefilter_products',
>          Field('product', db.products),
>          Field('thefilter', db.thefilter))
>
> And say we have:
> "Product1": "Tops", "Sweatshirts"
> "Product2": "Tops", "Sweatshirts", "Hoodie"
> "Product3": "Tops", "AthleticWear"
>
> And I wanted to get all products that at least contain the filters "Tops" 
> and "Sweatshirts", what would be the db().select() query to do this? The 
> desired result would return only "Product1" and "Product2".
>
> I tried using belongs, but that returned all products that included any of 
> the filter terms. I've also tried using the & on both the "Tops" and 
> "Sweatshirts" filter id ( db.thefilter_products==thefilter.id ), but this 
> returned an empty Set.
>

-- 

--- 
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.


Reply via email to