示例表:
db.define_table('pet',
Field('name'),
Field('owner_id','reference person'),
Field('location_id','reference location'))
1)如何检查位于"Furry"
的人15
拥有的宠物26
是否有?
2)如何检查位置8
中是否有76
的宠物?如果是这样,请退回。
答案 0 :(得分:0)
问题1
db((db.pet.name == 'Furry') & (db.pet.owner_id == 15) & (db.pet.location_id == 26)).count()
问题2
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()