>
> Hm, but how does it know to return a set object from the product_filter 
> table rather than the product or filter table?


Set objects are not associated with a particular table -- they represent a 
set of records to be returned by the db, which may involve a join of 
multiple tables. Basically, the Set object specifies the WHERE clauses in a 
SQL query.
 

> And what does these two queries mean when it comes executing the queries?
>     (db.products.id == db.product_filter.product_id) &
>     (db.filters.id == db.product_filter.filter_id) &
>

In SQL, there are two ways to specify an inner join -- one is by using the 
INNER JOIN (or just JOIN) command, and the other is by adding a WHERE 
clause that equates the primary key of one table with the associated 
foreign key from the other table. The above queries are using the latter 
method (in web2py, to use the former method, you pass the "join" argument 
to the .select() method).
 

> Does it work something like this: 
>
> Return the set object that contains the filter name "hoodie"
> (db.filters.name == "hoodie")
>
> Then, knowing the id of the filter from the previous result set, find all 
> the matching filter id in the product_filter table.
>  (db.filters.id == db.product_filter.filter_id)
>
> Now find all the products that has the same filter ids?
>  (db.products.id == db.product_filter.product_id) &
>

No, the above find products with id's that match the product_id of the 
records from db.product_filter, not that match the filter id's (there are 
no filter id's in the db.products table). As noted above, the immediately 
preceding two queries are used to join the db.product_filter table to the 
db.filters and db.products tables, respectively. This is necessary because 
this is a many-to-many relationship.

Anthony

-- 

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