#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 Ramiro Morales <rm0 _at_ gmx.net>):
Replying to [comment:23 Ramiro Morales <rm0 _at_ gmx.net>]:
> [...] I will attach another iteration of the patch where the
{{{tablename.filename}}} is rejected in the validation and all traces of
its support is eliminated from {{{QuerySet._get_sql_clause()}}}.
>
Done, see attached {{{ticket-2076.5.diff}}}
> This is the one I haven't the skills to implement.
[EMAIL PROTECTED] implemented it by calling the {{{lookup_inner}}}
function from {{{QuerySet._get_sql_clause()}}} but I don know what other
internal function should be used to take in account a recursive scenario
like this: The example at
http://www.djangoproject.com/documentation/db_api/ with the {{{Blog}}}
model having a {{{relname}}} relationship to a 4th model X and a
{{{Meta.ordering = (relname,)}}} and trying to order the {{{Entry}}} model
instances by its {{{blog}}} relationship field.
... or this better (worse?) scenario:
* The example at http://www.djangoproject.com/documentation/db_api/
* {{{Blog}}} model has a {{{relname}}} relationship to a 4th. model X
* its has {{{Meta.ordering = ('relname__a_field_from_model_X',)}}}
* We try to order the {{{Entry}}} model instances by its {{{blog}}}
relationship field.
>
> > 3. Check it works with all relations (not just !ForeignKeys).
> > 4. Let's work out what happens with backwards relations...
>
> I've added (although a bit contrived) test cases for both
{{{ManyToMany}}} and reverse {{{ForeignKey}}} and {{{ManyToMany}}}
relationships . Please verify the coverage of these tests.
>
Almost forgot to add this note: When creating the doctests for
{{{ManyToManyField}}} relationships I was getting
duplicate objects in the {{{order_by()}}} query results so I needed to
insert {{{distinct()}}} calls (see the last three tests), this may be sign
of an issue/shortcomming with the patch when interacting with that kind of
relationships. I can't compare this with any previous pre-patch behavior
because the {{{select_related()}}} workaround doesn't work in the M2M
case.
--
Ticket URL: <http://code.djangoproject.com/ticket/2076#comment:24>
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
-~----------~----~----~----~------~----~------~--~---