#29545: Nested OuterRef not looking on the right model for the field.
-------------------------------------+-------------------------------------
Reporter: Aaron Lisman | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: outerref, subquery | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):
* cc: Can Sarıgöl (added)
Comment:
IMO this query join order should be like this:
{{{
inner = Item.objects.filter(
middle = Invoice.objects.filter(
outer = Item.objects.filter(
}}}
If you want to use nested outerref, middle query has to contain foreign
keys. Otherwise, this usage needs to include deep related field.
{{{
middle = Item.objects.filter(invoices=OuterRef('id'),).annotate(
expensed=Exists(inner),
owner=F('invoices__owner')
).filter(expensed=False,)
}}}
or maybe not necessary nested outerref
{{{
inner = Invoice.objects.filter(
kind=Invoice.EXPENSE,
owner=OuterRef('invoices__owner'),
items=OuterRef('id'),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29545#comment:3>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.7003a06ef1b44663e062f0e042a7c12a%40djangoproject.com.