sorry, I didn't understood what you model was.
So, let's say you have
products table:
id name
1 "foo"
2 "bar"
and filters table:
id name
1 "top"
2 "sweatshirt"
3 "hoodie"
and a product_filter table
id product_id filter_id
1 1 1
2 1 2
3 2 3
so, basically, when you "de-normalize" it, it would be
"foo" is "top", "sweatshirt"
and
"bar" is "hoodie"
.
you want to find all products that have the "filter" equal to "top".
ok.
#all filters matching "hoodie"
myfilter = db(db.filters.name == "hoodie")
#all product_filters matching the previous id(s)
myfiltered_products =
db(db.product_filter.filter_id.belongs(myfilter._select(db.filters.id)))
#all products matching product_filter id(s)
top_products =
db(db.products.id.belongs(myfiltered_products._select(db.product_filter.product_id)))
print top_products.select()
However, it's a little bit cumbersome to this syntax, although its
perfectly working.
Another way can be
#linkage between the 3 tables
all_in_one = db(
(db.products.id == db.product_filter.product_id) &
(db.filters.id == db.product_filter.filter_id)
)
all_in_one_hoodies = all_in_one(db.filters.name == "hoodie").select()
#optionally, you can just select(db.products.ALL)
all_in_one_tops = all_in_one(db.filters.name == "top").select()
all_in_one_sweatshirts = all_in_one(db.filters.name == "sweatshirt").select
()
print 'hoodies', all_in_one_hoodies
print 'tops', all_in_one_tops
print 'sweatshirts', all_in_one_sweatshirts
Sorry for the misunderstanding .... I hope it's a bit clearer now.
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.