#6701: in qs-rf when many to many field referenced in order_by(), count() 
doesn't
match length of queryset
---------------------------------+------------------------------------------
   Reporter:  [EMAIL PROTECTED]    |                Owner:  nobody       
     Status:  closed             |            Component:  Uncategorized
    Version:  queryset-refactor  |           Resolution:  wontfix      
   Keywords:  qs-rf              |                Stage:  Unreviewed   
  Has_patch:  0                  |           Needs_docs:  0            
Needs_tests:  0                  |   Needs_better_patch:  0            
---------------------------------+------------------------------------------
Comment (by anonymous):

 If I have object A related to object B via an m2m and I want to return a
 results set of A sorted on an attribute of B then I'd expect to get
 repeats of objects of type A where its related to multiples of object B,
 e.g. what would be going on behind the scenes would be:

 SELECT contract.id, contract.name, supplier.name FROM contract,
 contract_supplier, supplier WHERE contract.id=contract_supplier.contract
 AND contract_supplier.supplier=supplier.id ORDER BY supplier.name

 Results:
 1 | Contract B | Supplier 1
 2 | Contract A | Supplier 2
 1 | Contract B | Supplier 3

 So I'd get two copies of the Contract B object. The suppliers field value
 on each of those copies would be exactly the same.

 And indeed this is what happens at present in qs-rf if I specify order_by
 on an attribute related via an m2m. It does not make sense UNLESS the
 results that query_set gives you are tagged with the order_by value that
 lead to the repetition. I'm not suggesting that the suppliers attribute on
 the contract object in the results from query_set be any different just
 because you're sorting on an attribute of the supplier objects - which I
 think is what you mean by "doesn't make sense mathematically"? In my use
 case I'd need a way of getting at the order_by column value so I can
 display to the user what supplier is relevant to the position of that
 contract result in the set (which is what my django users post was about).

 Stepping back from what an order_by of "supplier__name" means, I
 personally would find it useful (as I've said) to be able to have a way to
 order a result set by an m2m field and get at value of that m2m field that
 corresponds to a given entry in the result set - it may be that the
 "django way" of doing that is to use .extras(), which is fair enough.

 My apologies if this is the wrong place to discuss this!

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