在PonyORM中,有两种方法可以逐步组合查询。第一个是
filter
查询方法:
def where_entry_category(query, category, recourse)
if category:
category = str(category)
if recurse:
query = query.filter(lambda x: x.category == category or
x.category.startswith(category + '/')
else:
query = query.filter(lambda x: x.category == category)
return query
query = Entry.select()
query = where_entry_category(query, "test")
从0.7.6版开始,还可以使用以前的查询作为新查询的源:
def where_entry_category(query, category, recourse)
if category:
category = str(category)
if recurse:
query = select(x for x in query
if x.category == category or
x.category.startswith(category + '/'))
else:
query = select(x for x in query if x.category == category)
return query
or
条款逐渐在将来发布。