#2076: order_by with related table does not work
---------------------------+------------------------------------------------
   Reporter:  mtredinnick  |                Owner:  mtredinnick     
     Status:  new          |            Component:  Database wrapper
    Version:  SVN          |           Resolution:                  
   Keywords:               |                Stage:  Accepted        
  Has_patch:  1            |           Needs_docs:  0               
Needs_tests:  0            |   Needs_better_patch:  1               
---------------------------+------------------------------------------------
Comment (by anonymous):

 I'm a Django newbie and innocently stumbled into the recursive case that
 Ramiro mentioned:
 
 {{{
 class A(models.Model):
     ...
 
 class B(models.Model):
     a = models.ForeignKey(A)
     ...
     class Meta:
         ordering = ('a',)
 
 class C(models.Model):
     b = models.ForeignKey(B)
     ...
     class Meta:
         ordering = ('b',)
 }}}
 
 In svn trunk, trying to list Cs in the admin interface gave me a MySQL
 error that there was no field app_b.a
 
 Because A just orders by the PK anyway, I was able to work around it by
 specifying 'a_id' in for B's ordering (though this raises an error in
 model validation that B has no 'a_id' field):
 
 {{{
 class B(models.Model):
     a = models.ForeignKey(A)
     ...
     class Meta:
         ordering = ('a_id',)
 }}}
 
 Just for kicks, I applied ticket-2076.6 patch, and now it won't work
 either way.  The original code errors out looking for app_c.app_b.a and
 the hacked code looks for app_c.app_b.a_id
 
 I know you're already aware that this is a problem with the patch.  Just
 chiming in to note that this two-layer FK relationship is quite natural
 and easy to write, even for a beginner, so I would think that it needs to
 Just Work in 1.0.

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