Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Anssi Kääriäinen
On Saturday, July 5, 2014 1:47:30 AM UTC+3, Jon Dufresne wrote: > Sorry, but I felt like I was reporting information interesting to > developers. > > 1.) Wrong JOIN type (OUTER vs INNER) producing inefficient queries > 2.) FieldError in 1.7 where there wasn't one in 1.6 > > If these are of n

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Anssi Kääriäinen
On Saturday, July 5, 2014 12:42:39 AM UTC+3, Jon Dufresne wrote: > > Suppose I have the following models: > > --- > class Container(models.Model): > pass > > class Item(models.Model): > container = models.ForeignKey(Container) > previous = models.ForeignKey('self', null=True) >

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Jon Dufresne
> ... and this is more appropriate on django-users Sorry, but I felt like I was reporting information interesting to developers. 1.) Wrong JOIN type (OUTER vs INNER) producing inefficient queries 2.) FieldError in 1.7 where there wasn't one in 1.6 If these are of no interest, I will not continue

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Javier Guerra Giraldez
On Fri, Jul 4, 2014 at 5:23 PM, Stephen J. Butler wrote: > * Build a list of relevant containers first: > Container.objects.filter(item__previous__isnull=True, > item__flag=True).values_list('pk', flat=True). Then > Items.objects.filter(current=True, container__in=flagged_containers). Not a > prob

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Stephen J. Butler
On Fri, Jul 4, 2014 at 4:42 PM, Jon Dufresne wrote: > Suppose I have the following models: > > --- > class Container(models.Model): > pass > > class Item(models.Model): > container = models.ForeignKey(Container) > previous = models.ForeignKey('self', null=True) > current = models.

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Jon Dufresne
On Fri, Jul 4, 2014 at 2:54 PM, Javier Guerra Giraldez wrote: > what purpose does the "container__item__previous__isnull=True" > argument serve here? To filter on the initial item in the list. I'm looking for flag=True *only* on the first item in the list. flag=True could be set on other items in

Re: Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Javier Guerra Giraldez
On Fri, Jul 4, 2014 at 4:42 PM, Jon Dufresne wrote: > Item.objects.filter(current=True, > container__item__previous__isnull=True, container__item__flag=True) > --- > > That is, I'm looking for all current items such that the first item in > the chain has flag = true. Django 1.6 produces the follow

Querying across FK produces too many OUTER JOINs (1.6) or FieldError (1.7)

2014-07-04 Thread Jon Dufresne
Suppose I have the following models: --- class Container(models.Model): pass class Item(models.Model): container = models.ForeignKey(Container) previous = models.ForeignKey('self', null=True) current = models.BooleanField() flag = models.BooleanField() --- Item represents a c