M, thanks. But should I create ticket on django trac about this issue? On 17 ноя, 17:29, Tom Evans <tevans...@googlemail.com> wrote: > On Tue, Nov 17, 2009 at 3:17 PM, Ilya <ilblackdra...@gmail.com> wrote: > > I just developed some code like: > > MyModel.objects.filter(key_to_mymodel2 = MyModel2.objects.all())) > > This query produce SQL: > > SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id =(select `id` > > from `test_mymodel2`) > > > It works fine on SQLLite, but in MySQL it produce error: > > OperationalError: (1242, 'Subquery returns more than 1 row') > > MySQL to work need query: > > SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id = ANY (select > > `id` from `test_mymodel2`) > > > Of course I can make something like: > > list = MyModel2.objects.all() > > res = [] > > for x in list: > > res += MyModel.objects.filter(key_to_mymodel2 = x) > > > It there any other path to solve this? > > > -- > > This would also work: > > MyModel.objects.filter(key_to_mymodel2__in=MyModel2.objects.all().values_list('id', > flat=True))) > > Cheers > > Tom
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.