我有两个简单的类映射现有数据库:
class File(object):
__storm_table__ = 'files'
fid = Int(primary=True)
filename = Unicode()
class FileDownload(object):
__storm_table__ = 'filefield_track'
did = Int(primary=True)
fid = Int()
email = Unicode()
date = DateTime()
trackedfile = Reference(fid, File.fid)
File.filedownloads = ReferenceSet(File.fid, FileDownload.fid)
我只想找到所有的File
对象,这些对象有一个非空的File.filedownloads
集。在python中,只需查询所有File
对象并手动过滤File.filedownloads
字段,就可以做到这一点,但我认为有一种更干净的方法可以做到这一点(这行不通:):
我知道第一个在SQLAlchemy中工作:
session.query(File).filter(File.filedownloads != None)
我找到了一个处理内部ID(fid)的“肮脏”解决方案
相关问题 更多 >
编程相关推荐