Erm, and the queryset creation.

Also, people are en route to PyCon, so responses may be a bit slow.

On Wed, Feb 17, 2010 at 3:30 PM, [email protected] <[email protected]> wrote:
> http://dpaste.com/160722/
>
> class Contact(models.Model):
>    program = models.ForeignKey('agency.Program')
>    consumer =
> models.ForeignKey('consumer.Consumer',null=True,blank=True)
>    date = models.DateField('Contact Date')
>    notes = models.TextField()
>    date_added = models.DateTimeField(editable=False)
>    method =
> models.CharField(max_length=10,choices=choices.CONTACT_METHOD,\
>            null=True,blank=True)
>
> # consumer_contact
> class Contact(basemodels.Contact):
>    base = models.OneToOneField(basemodels.Contact,
> parent_link=True,related_name="consumer_contact")
>    service = models.ForeignKey(Service)
>    confidential = models.BooleanField(default=False,help_text='These
> notes will not be visible to general staff')
>    group = models.ForeignKey(Group,null=True,blank=True)
>    group_contact =
> models.ForeignKey('consumer.GroupContact',blank=True,null=True)
>
>    def save(self, *args, **kwargs):
>        super(Contact, self).save(*args,**kwargs)
>
>    class Meta:
>        permissions = (
>            ("allow_confidential", "Can make contacts confidential"),
>        )
>
> #ir_contact
> class Contact(basemodels.Contact):
>
> base=models.OneToOneField(BaseContact,parent_link=True,related_name='IR_contact')
>    IR=models.ForeignKey(IR,blank=True,null=True)
>
> referred_from=models.ForeignKey(ReferralSource,related_name='IR_referred_from')
>
> referred_to=models.ManyToManyField(ReferralSource,related_name='IR_referred_to')
>
> information=models.ManyToManyField(Information,verbose_name='Information
> Requested')
>
>
> On Feb 17, 4:15 pm, Jeremy Dunck <[email protected]> wrote:
>> We'll need your model definitions in order to help much.
>>
>> On Wed, Feb 17, 2010 at 2:54 PM, Steve <[email protected]> wrote:
>> > Hello all,
>>
>> > I believe select_related is creating some extraneous joins in situations
>> > where one is joining child models from a base model (model inheritance).
>>
>> > Take the following SQL generated (dpaste here, probably more readable
>> >http://dpaste.com/160677/)
>>
>> > ====
>>
>> > SELECT (fields) FROM `base_contact`
>>
>> > LEFT OUTER JOIN `consumer_consumer` ON (`base_contact`.`consumer_id` =
>> > `consumer_consumer`.`id`) # ok
>>
>> > INNER JOIN `agency_program` ON (`base_contact`.`program_id` =
>> > `agency_program`.`id`) # ok
>>
>> > LEFT OUTER JOIN `consumer_contact` ON (`base_contact`.`id` =
>> > `consumer_contact`.`base_id`) # ok
>>
>> > INNER JOIN `base_contact` T5 ON (`consumer_contact`.`base_id` = T5.`id`) #
>> > ?!?
>>
>> > # These next two are questionable, since they are joined on a LEFT OUTER 
>> > (so
>> > they may potentially not be there)
>>
>> > INNER JOIN `consumer_service` ON (`consumer_contact`.`service_id` =
>> > `consumer_service`.`id`)
>>
>> > INNER JOIN `consumer_servicetype` ON (`consumer_service`.`type_id` =
>> > `consumer_servicetype`.`id`)
>>
>> > LEFT OUTER JOIN `IR_contact` ON (`base_contact`.`id` =
>> > `IR_contact`.`base_id`)  # ok
>>
>> > INNER JOIN `base_contact` T9 ON (`IR_contact`.`base_id` = T9.`id`) # ?!?
>>
>> > WHERE `consumer_consumer`.`file` = 06-1757 ORDER BY `base_contact`.`date`
>> > DESC
>>
>> > ====
>>
>> > There are two joins I simply can't explain (marked "?!?"). Removing them
>> > gives me my expected results. select_related in on case seems to correctly
>> > create a LEFT OUTER, but then follows up by creating an unwanted INNER.
>>
>> > Keep in mind I made a note about the 'questionable' join above, but even
>> > removing that entirely creates the same problem.
>>
>> > I'll be glad to file a ticket, if the issue is something other than my
>> > ignorance.
>>
>> > -Steve
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups
>> > "Django developers" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> >http://groups.google.com/group/django-developers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/django-developers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to