2011-08-11 58 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第一個,等等)。

相關問題