Question

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.

Était-ce utile?

La solution

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top