works!

Thanks Jim!

On Thursday, March 10, 2016 at 9:55:33 AM UTC-5, Jim S wrote:
>
> Maybe something like this?  (not tested)
>
> already_owns = db(db.owns.person == person_id)._select(db.owns.thing)
>
> things_not_owned = db(~db.thing.id.belongs(already_owns)).select()
>
>
> -Jim
>
> On Thursday, March 10, 2016 at 8:49:32 AM UTC-6, Paul wrote:
>>
>> Does anyone know if there is a way to perform set difference (ie the 
>> elements in set A that are not in set B) using database queries / DAL?
>>
>> for example if you had some tables defined like this:
>>
>> db.define_table('thing',
>>                Field('name'))
>>
>> db.define_table('owns',
>>                Field('person', 'reference auth_user'),
>>                Field('thing', 'reference thing'))
>>
>>
>> and you want to find a list of all the things that person X doesn't yet 
>> own.
>>
>> The "easy" way would be to query for a set of all the "thing"s and then 
>> do a separate query for all the "thing"s owned by person X, create python 
>> set objects and use the set difference operator. 
>>
>>
>> I'm wondering if there is a way to do this as a single db query? 
>>
>> Thanks!
>>
>> Paul
>>
>>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to