#36954: Filtering an ManyToManyField causes the `.values` call to be filtered
-------------------------------------+-------------------------------------
Reporter: Ryan "RB" Barnes | Owner: Mahi
| Singhal
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* resolution: => invalid
* status: assigned => closed
Comment:
There's no bug here please refer to
TicketClosingReasons/UseSupportChannels
Your second query literally generate
{{{#!sql
SELECT technician_id
FROM appointment
INNER JOIN appointment_technicians ON (
appointment_technicians.appointment.id = appointment.id
)
WHERE
appointment.id = ?
AND appointment_technicians.technician_id IN ?
}}}
If you're interested in all technicians for a particular appointment where
a particular technician is you effectively need to use `Exists`
{{{#!python
Appointment.objects.filter(
Exists(
Technician.objects.filter(
id=tech_1,
appointments__in=OuterRef("pk"),
)
),
id=appointment.id,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36954#comment:2>
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 visit
https://groups.google.com/d/msgid/django-updates/0107019c9b32f15d-f9f5acad-892f-428d-a0be-6a3c450bf874-000000%40eu-central-1.amazonses.com.