#29338: Can't use OuterRef in union Subquery
-------------------------------------+-------------------------------------
Reporter: Matthew Pava | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Can Sarıgöl):
> {{{
> cls = Document.objects.filter(
> checklist__isnull=False,
> part=OuterRef('id')
> ).values('checklist__customer', 'created')
>
> ots = Document.objects.filter(
> ownershiptransfer__isnull=False,
> part=OuterRef('id')
> ).values('ownershiptransfer__ship_target__contact', 'created')
>
> return self.annotate(
> owner=Subquery(cls.union(ots).values('owner')[:1])
> )
> }}}
I change the example like this:
{{{
cls = Document.objects.filter(
checklist__isnull=False,
).values('checklist__customer', 'created')
ots = Document.objects.filter(
ownershiptransfer__isnull=False,
).values('ownershiptransfer__ship_target__contact', 'created')
return self.annotate(
owner=Subquery(cls.union(ots).filter(part=OuterRef('id')).values('owner')[:1])
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29338#comment:6>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.aabf9fe130b47b7ef1bbbf0472236465%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.