Use straight sql. There are always potentially limitations with an abstraction such as the ORM.
Why try to fit a square peg into a round whole. On Wednesday, March 21, 2012 4:41:32 AM UTC-4, diafygi wrote: > > There is an old thread that didn't end in a resolution about > preventing joins in a filter(foreign_key=None) scenario. > > > http://groups.google.com/group/django-users/browse_thread/thread/61ee2fb22deae326 > > > I'd like to bring it up again and ask if there is now a way to prevent > joins from a query. > > An example: > class Blog(model.Models): > editor = models.ForeignKey(User, null=True) > > # find all the blogs with no editors > >>> Blog.objects.filter(editor=None) > DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM > `myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id` > = `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL; > > # Is there a way to do this query? > >>> Blog.objects.filter(editor=None) > DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM > `myapp_blog` WHERE `myapp_blog`.`editor_id` IS NULL; > > Thanks! > Daniel -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/NfvXnYxnHBkJ. To post to this group, send email to django-users@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=en.