Hm, but how does it know to return a set object from the product_filter
table rather than the product or filter table?
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) &
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) &
But then why even do the last part? Wouldn't db.filters.id ==
db.product_filter.filter_id already give you the rows you'd want from
product_filter table?
On Tuesday, May 21, 2013 4:19:29 PM UTC-4, Anthony wrote:
>
> Note, I'm not sure the fact that a Set is callable is documented in the
> book.
>
> On Tuesday, May 21, 2013 4:14:48 PM UTC-4, Anthony wrote:
>>
>> db(some_query) creates a DAL Set object (on which you can then call
>> methods such as .select(), .update(), etc.). A Set object is also callable,
>> and if you call it by passing in another query, it will simply add the new
>> query as an AND condition. So, that code is just equivalent to:
>>
>> db(
>> (db.products.id == db.product_filter.product_id) &
>> (db.filters.id == db.product_filter.filter_id) &
>> (db.filters.name == "hoodie")
>> )
>>
>> or
>>
>> db(db.products.id == db.product_filter.product_id)(db.filters.id == db.
>> product_filter.filter_id)\
>> (db.filters.name == "hoodie")
>>
>> The idea is that you can create a base Set object and then use it to
>> create more specific sets by adding different conditions.
>>
>> Anthony
>>
>> On Tuesday, May 21, 2013 4:02:00 PM UTC-4, [email protected] wrote:
>>>
>>> Is there a section in the online web2py book that explains Niphlod's
>>> way to building a query?
>>>
>>> Near the bottom of this
>>> thread<https://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA>
>>> there
>>> is:
>>>
>>> all_in_one = db(
>>> (db.products.id == db.product_filter.product_id) &
>>> (db.filters.id == db.product_filter.filter_id)
>>> )
>>>
>>> Then to get all corresponding rows in product_filter table,
>>>
>>> all_in_one_hoodies = all_in_one(db.filters.name == "hoodie").select()
>>>
>>> I understand his cumbersome example, where you have to select a
>>> resultset and then pass that to another select(). But I don't understand
>>> how I can pass all_in_one() a parameter and how it knows to return all
>>> products which have the "hoodie" filter name.
>>>
>>>
>>>
--
---
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.