ids = "1,2,3,4"
idlist = [int(i) for i in ids.split(',')] # [4, 1, 2, 3]
jobs = Job.select().join(User).distinct().where(Job.id << idlist).dicts()

if (jobs.count()):
        for i, job in enumerate(jobs):
            print str(i) + " : " + str(job['id'])

returns :

0 : 1
1 : 2
2 : 1
3 : 2
4 : 3
5 : 4

expected:

0 : 1
1 : 2
2 : 3
3 : 4

What is causing this? jobs.count() returns 4. I even added distinct() but seems like none of it is making an impact, really confusing.

有帮助吗?

解决方案

With sqlite if you are saving inside the loop, this may be the issue:

https://github.com/coleifer/peewee/issues/12#issuecomment-5614404

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top