#4957: Query for ForeignKey using implicit exact and to_field breaks
---------------------------------+------------------------------------------
          Reporter:  jdunck      |         Owner:  adrian        
            Status:  new         |     Component:  Core framework
           Version:  SVN         |      Keywords:                
             Stage:  Unreviewed  |     Has_patch:  0             
        Needs_docs:  0           |   Needs_tests:  0             
Needs_better_patch:  0           |  
---------------------------------+------------------------------------------
 Given these models:
 {{{
 class District(models.Model, models.GeoMixin):
     tea_number = models.CharField(maxlength=20, unique=True)
 
 class School(models.Model, models.GeoMixin):
     district = models.ForeignKey(District, to_field='tea_number')
 }}}
 
 I expect this to work:
 {{{
 a_district = District.objects.all()[0]
 Schools.objects.filter(district=a_district)
 }}}
 So that a_district's tea_nuumber attribute is used for the criteria
 against the School table rather than the District's PK.
 
 django.db.models.query.lookup_inner (line 1082) has the bug:
 {{{
                 # RelatedObject is from a 1-1 relation,
                 # No need to join; get the pk value from the related
 object,
                 # and compare using that.
                 column = current_opts.pk.name
 }}}
 
 I'll try to work up a patch for it.  Tired now.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4957>
Django Code <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