On May 1, 2008, at 11:49 AM, [EMAIL PROTECTED] wrote:
> >> Now that QSRF has landed, this type of thinking leads me to: who's >> working on 121-rewrite? > > I'm fairly certain that in refactoring QuerySet, OneToOneField has > been fixed. It's the base mechanism that allows multi-table > subclassing to work, in fact. I do not believe you understood what I mean by fixed. OneToOneField has always worked, halfway. What it doesn't do is follow the relationship in both directions: from django.db import models class A(models.Model): a1 = models.CharField(max_length=20) class B(models.Model): b1 = models.CharField(max_length=20) b2 = models.OneToOneField(A) B.objects.select_related() creates this query (MySQL, taken from the logs): SELECT `t1_b`.`id`, `t1_b`.`b1`, `t1_b`.`b2_id`, `t1_a`.`id`, `t1_a`.`a1` FROM `t1_b` INNER JOIN `t1_a` ON (`t1_b`.`b2_id` = `t1_a`.`id`) A.objects.select_related() creates this query: SELECT `t1_a`.`id`, `t1_a`.`a1` FROM `t1_a` A complete OneToOneField would generate effectively the same query in both directions, since it's a special type of ForeignKey that the reverse relationship makes sense to automatically select on. If this worked, then in the User case, you could select_related() on the UserProfile, *OR* .select_related() on the User(), and you would get the same data either way, no matter how many models were connected via OneToOneField in this manner. I would assume that all the normal .select_related(***) options would work as well across this, like "depth" and the new options for picking a subset of fields only to follow the relations on. (As an aside, forward FKs on both sides of the OneToOne should be followed, but that I would assume is an incidental of getting OneToOnes working this way in the first place). Does that make more sense as to why it would alleviate the issue? Thanks, gav --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---