2011-08-11 55 views

回答

2

您可以查询稍多加入.Count中()来结束

前最佳:0回报< s.query(关键字).filter(kw.word == kw.word ).Count之间的()

0

一个Python的方式,我喜欢做它:

query = session.query(Model).filter(...) 
try: 
    model = query.one() 
except NoResultFound: 
    # it does not exist! 
except MultipleResultsFound: 
    # there are more than one matching the filter criteria! 

这样,比如说,创建新模型时,不存在一个,并警告用户,如果存在多个的人(选择f第一个,等等)。

相关问题