我正在处理一张用户表。
我有 2 个列表。第一个由 ID 组成,它必须在答案中并且必须排在第一位。第二个由 ID 组成,不应该在答案中。
在这种情况下,分页应该有效。
我尝试将查询拆分为 2 个查询并使用“UNION”,它有效但结果分散。
`find_ids = [5, 6, 7]
exclude_ids = [2]
query1 = User.query.filter(User.id.in_(find_ids) & User.id.notin_(exclude_ids))
query2 = User.query.filter(User.id.notin_(find_ids) & User.id.notin_(exclude_ids))
return query1.union(query2).paginate(page=page, per_page=per_page)`
在这个例子中,我期望元素的 id 是这样的:
[5, 6, 7, 1, 3, 4, 8, 9, 10, ...]