0
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.

KJW
  • 15,035
  • 47
  • 137
  • 243

1 Answers1

1

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

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

coleifer
  • 24,887
  • 6
  • 60
  • 75
  • I tried it with `Job.select().distinct().where(Job.user == current_user.id, Job.id << idlist).dicts()` getting exact same result – KJW May 05 '14 at 19:02