#7270: selected_related() can not follow reverse relations of OneToOne.
---------------------------------------------------+------------------------
          Reporter:  [email protected]          |         Owner:  
mtredinnick                    
            Status:  new                           |     Milestone:  1.2        
                    
         Component:  Database layer (models, ORM)  |       Version:  SVN        
                    
        Resolution:                                |      Keywords:  
select_related onetoone reverse
             Stage:  Accepted                      |     Has_patch:  1          
                    
        Needs_docs:  0                             |   Needs_tests:  1          
                    
Needs_better_patch:  1                             |  
---------------------------------------------------+------------------------
Comment (by bendavis78):

 I've attached a version of the patch against r10396.

 Also, I modified the self.join() call to set promote=True so that LEFT
 OUTER joins are always used -- although I'm not sure if that was all I
 needed to do, as I'm seeing a problem with the returned queryset when some
 of the joined values are null.

 For example,  let's say we have some User records that don't have
 associated !UserProfile records.  When we do:
 {{{
 >>> print User.objects.select_related('userprofile').query.as_sql()[0]
 'SELECT `auth_user`.`id`, `myapp_userprofile`.`id`, FROM `auth_user` LEFT
 OUTER JOIN `myapp_userprofile` ON (`auth_user`.`id` =
 `myapps_userprofile`.`user_id`)'
 }}}
 ... we get the correct SQL,  and running this in dbshell returns the
 correct results, with the columns from !UserProfile set to NULL.

 However, when we try to output the queryset object,  we get an empty list:
 {{{
 >>> q = User.objects.select_related('user_profile')
 >>> q
 []
 >>>
 }}}
 Any ideas on why this is occurring?

 Also, I've noticed some other problems that come up when we .values() or
 .only()  on the query set,   so I think this patch needs a little more
 refining before we can get it to work.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7270#comment:32>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to