2013-01-02 1 views
3

나는이 개 간단한 클래스 매핑 기존 DB가 있습니다. 이것은 단지 모든 File 개체를 쿼리하고 수동으로 File.filedownloads 필드를 필터링하여 파이썬에서 수행,하지만 난이 할 수있는 청소기 방법 (이 작동하지 않습니다 :))이라고 생각 할 수 있습니다파이썬 스톰 쿼리 ReferenceSet (일대)

store.find(File, File.filedownloads != None) 
store.find(File, File.filedownloads.count() != 0) 

내가 알고를 첫 번째 SQLAlchemy의 작동합니다

session.query(File).filter(File.filedownloads != None) 

답변

1

나는 내부 아이디 (FID) 처리는 '더러운'해결,

# Find all files that have been downloaded 
subselect = Select(FileDownload.fid, distinct=True) 
for f in store.find(File, File.fid.is_in(subselect)): 
    print(f.filename, f.filedownloads.count()) 
을 찾을 수 있었다