#11319: ForeignKey filters use the wrong field to prepare values for database
---------------------------------------------------+------------------------
          Reporter:  russellm                      |         Owner:  carljm
            Status:  new                           |     Milestone:  1.3   
         Component:  Database layer (models, ORM)  |       Version:  1.0   
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  1                             |  
---------------------------------------------------+------------------------
Comment (by carljm):

 Discussed this with Alex Gaynor on IRC. Using this Category class as an
 example, we're both agreed that the first fix results in more intuitive
 usage:

 {{{
 class Category(models.Model):
     name = models.CharField(max_length=10)
     parent = models.ForeignKey("self", to_field="name",
 related_name="children")
 }}}

 With either fix, you can query it this way in the forward direction:
 `Category.objects.filter(parent="Kittehs")` and can query it using a full
 Category object in either direction.

 Currently, and if we make the second fix, you have to query in the reverse
 direction using the PK: `Category.objects.filter(children=1)`

 Whereas if we make the first fix, you could query like this:
 `Category.objects.filter(children="Noms")`

 Seems clear that the latter is more intuitive. And it requires the less-
 invasive fix (which I've pushed to
 https://github.com/carljm/django/compare/master...t11319-simpler for
 comparison).

 I'd be in favor of making this fix; my only remaining question is whether
 the backwards-incompatible change is a concern. It's a very rare edge case
 of an edge case: I think we can safely call it part of a bugfix.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11319#comment:16>
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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to