Does this work: owned_licenses = dba()._select(dba.owned_license.license_id, distinct=True) unowned_licenses = dba(~dba.license.license_id.belongs(owned_licenses)). select()
Also, do you need the license_id to be in a particular format? If not, maybe get rid of that field and just use the db.license.id field as the unique identifier for each license. The db.owned_license.license_id field can then be a reference field to the db.license table: dba.define_table('license', Field('name', 'integer'), format='%(name)s') dba.define_table('owned_license', Field('owner_id', 'integer'), Field('license', 'reference license')) owned_licenses = dba()._select(dba.owned_license.id, distinct=True) unowned_licenses = dba(~dba.license.id.belongs(owned_licenses)).select() If there is a dba.owner table, then dba.owned_license.owner_id should probably be a reference field to that table as well (so dba.owned_license becomes a link table for the many-to-many relationship between licenses and owners). Anthony On Sunday, May 18, 2014 9:34:28 AM UTC-4, Lucas Schreiber wrote: > > Hey, > i have another Problem. Imagine you have two rows created as follow: > > models: > > > dba.define_table('owned_license', > Field('owner_id', 'integer'), > Field('license_id', 'integer')) > > > dba.define_table('license', > Field('license_name', 'integer'), > Field('license_id', 'integer')) > > > Controller: > > owned_license_db = dba(dba.owned_license.owner_id== owner_id).select(dba. > owned_license.ALL) > license_db = dba().select(dba.license.ALL) > > > Inserts in the db (for example): > > dba.license.insert(license_id= 1, license_name= 'test1') > dba.license.insert(license_id= 2, license_name= 'test2') > dba.license.insert(license_id= 3, license_name= 'test3') > dba.license.insert(license_id= 4, license_name= 'test4') > dba.license.insert(license_id= 5, license_name= 'test5') > > > dba.owned_license.insert(owner_id = 1, license_id= 2) > dba.owned_license.insert(owner_id = 1, license_id= 3) > dba.owned_license.insert(owner_id = 1, license_id= 4) > dba.owned_license.insert(owner_id = 2, license_id= 1) > dba.owned_license.insert(owner_id = 2, license_id= 3) > > > > > in this example, if i have owner_id =1, i want a row with every row from > license_db not in owned_license_db, so, in this example, 1 and 5. > > How can this be done? > > Thanks for every help :) > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.