web2py:检查是否记录在数据库中?

web2py: Check if record in database?

示例table:

db.define_table('pet',
    Field('name'),
    Field('owner_id','reference person'),
    Field('location_id','reference location'))

1) 我如何检查位置 26 的人 15 是否拥有名为 "Furry" 的宠物?

2) 如何查看位置 76 是否有人 8 的宠物?如果是这样,return 他们。

问题 1

db((db.pet.name == 'Furry') & (db.pet.owner_id == 15) & (db.pet.location_id == 26)).count()

问题二

db((db.pet.owner_id == 8) & (db.pet.location_id == 76)).count()

# if you have the name of the owner and the location you can even do 

db((db.pet.owner_id == 
    db(db.person.name == 'NO_8_PERSON_NAME'
       ).select(db.persone.id).first().id) & 
   (db.pet.location_id == 
    db(db.location.location_name == 'NO_76_LOCATION_NAME'
       ).select(db.location.id).first().id)).count()