#2080 closed defect (duplicate)
OR lookup across many-to-one relationships gives unexpected results
| Reported by: | Antti Kaihola | Owned by: | Adrian Holovaty |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | mir@…, mattimustang@…, yannvr@… | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
If
- model
Bhas a foreign key on modelA, - there is an
a1 = A(field1=value1)object but no relatedBobjects
and you do
A.objects.filter(Q(field1=value1) | Q(b__field2=value2))
the result will fail to include a1.
This is quite unexpected in my opinion, and I think the reason is that the resulting SQL query uses an inner join instead of an outer join.
Attachments (2)
Change History (9)
by , 19 years ago
| Attachment: | m2o_or_lookup_test.diff added |
|---|
comment:1 by , 19 years ago
This might be the same issue as in ticket #1535, although that seems to be already fixed but it doesn't fix this.
by , 19 years ago
| Attachment: | m2o_or_lookup_test.2.diff added |
|---|
Added testing with alternate syntax and checking what kind of join Django uses
comment:3 by , 19 years ago
| Cc: | added |
|---|
comment:4 by , 19 years ago
| Cc: | added; removed |
|---|
comment:6 by , 18 years ago
| Cc: | added |
|---|
comment:7 by , 18 years ago
| Cc: | added |
|---|
Note:
See TracTickets
for help on using tickets.
a test case for an OR lookup across a foreign key relation