I think that while `extra()` gets a bad rap, it is extremely useful when 
creating generic pluggable apps, and I for one would miss it if it were to 
be removed.

In a comment on #7231 a few years ago I wrote:

I can't reply to the discussion linked on Google Groups anymore, but wanted 
> to add my comment that I have found many uses for .extra() and also hit the 
> limitation of being unable to add left outer joins to a query generated by 
> the ORM. I would not like to see it disappear in favour of raw SQL.
>

> My current use case is for joining reverse generic relations on queries 
> against a model that does not have a GenericRelation field back to the 
> generic model (because I don't know which models it will be used with -- I 
> can't add models to 3rd party code).
>

> To require the whole query in raw SQL in order to join generic relations 
> would mitigate the pluggability of the generic model in question.


While `raw()` may be allow you to get model instances from any custom SQL, 
it will often be prohibitively complicated or impossible to provide generic 
queryset methods that extend 3rd party apps. The RawSQL expression example 
given would appear to execute a subquery for each row of the result set. It 
wouldn't seem to help with the example above, unless I'm missing something?

Cheers.
Tai.


On Monday, August 3, 2015 at 5:27:14 PM UTC+10, Anssi Kääriäinen wrote:
>
> You can annotate raw SQL with expressions. I think the only case that 
> can't be done with expressions is addition of extra tables to the query. I 
> am certain we will get a solution to this too in future releases.
>
>  - Anssi
>
> On Friday, July 31, 2015 at 9:01:45 PM UTC+3, Andres Osinski wrote:
>>
>> Would the expressions API be able to define fields that are aggregations 
>> of complex foreign relationships? I keep using it when I need fields that 
>> are the result of weird aggregations over multiple JOINs with some unusual 
>> stuff like CASE fields and subqueries.
>>
>> On Fri, Jul 31, 2015 at 2:58 PM, Tim Graham <timog...@gmail.com> wrote:
>>
>>> In light of the new expressions API, the idea of deprecating 
>>> QuerySet.extra() has been informally discussed in IRC and elsewhere. I 
>>> wonder if there is consensus to mark extra() as "unmaintained" and to 
>>> suggest filing feature requests for functionality that can be performed 
>>> through extra() but not through other existing QuerySet methods? There are 
>>> at least several tickets (examples below) of edge cases that don't work 
>>> with extra(). It seems like a waste of time to leave these tickets as 
>>> accepted and to triage new issues with extra() if they won't be fixed.
>>>
>>> https://code.djangoproject.com/ticket/24142
>>> https://code.djangoproject.com/ticket/19434
>>> https://code.djangoproject.com/ticket/12890
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django developers (Contributions to Django itself)" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-develop...@googlegroups.com.
>>> To post to this group, send email to django-d...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-developers.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-developers/6e1be326-3b17-49ca-accf-03eec5ad41ef%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-developers/6e1be326-3b17-49ca-accf-03eec5ad41ef%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Andrés Osinski
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0613b9fc-358d-4aec-99e3-cec2d4fe9894%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to