#14056: Wrong query generated when using reverse foreign key
---------------------------------------------------+------------------------
          Reporter:  premalshah                    |         Owner:  nobody     
            Status:  new                           |     Milestone:  1.3        
         Component:  Database layer (models, ORM)  |       Version:  1.0        
        Resolution:                                |      Keywords:  foreign key
             Stage:  Unreviewed                    |     Has_patch:  0          
        Needs_docs:  0                             |   Needs_tests:  0          
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by premalshah):

  * version:  0.96 => 1.0

Comment:

 '''Clarifications on the version #:'''
 I've changed the version to 1.0 since that is what Im using right now and
 also because lot of people on the django IRC channel complained about the
 version #. But I have seen the same behavior in 0.96, 1.1 and 1.2.

 '''Clarifications for Query 1:'''

 Most people on the django IRC channel said "The join is not required and
 so django removes it." To concentrate on issues with Query 2 and 3, I
 would agree.

 '''Clarifications for Query 2:'''

 There is a multi-column index on fields obj_id, field1 which speeds up the
 query quite a bit. Query 2 is a query optimization issue.

 '''Evidence for wrong query results for Query 3:'''

 Please add this to the class called "Base"
 {{{
     def __str__(self):
         return self.field1
 }}}

 Now execute this:
 {{{
 b = Base(field1='ABC')
 b.save()
 c1 = Child(obj=b, field1='a', field2=1)
 c2 = Child(obj=b, field1='b', field2=2)
 c3 = Child(obj=b, field1='c', field2=3)
 c1.save()
 c2.save()
 c3.save()

 Base.objects.filter(child__obj=1,
 child__field1='a').order_by('child__field2', 'child__obj')
 >>> [<Base: ABC>, <Base: ABC>, <Base: ABC>]

 The actual result should be
 >>> [<Base: ABC>]
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14056#comment:2>
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