#33838: Querying issue with ForeignKeys where db_constraint=False
-------------------------------------+-------------------------------------
Reporter: Alex Bailey | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alex Bailey):
I just noticed that adding `null=True` to the ForeignKeys produces the
expected result on the last query:
{{{
class Book(models.Model):
foo = models.ForeignKey(Person, db_constraint=False,
on_delete=models.DO_NOTHING, related_name='foo', null=True)
bar = models.ForeignKey(Person, db_constraint=False,
on_delete=models.DO_NOTHING, related_name='bar', null=True)
}}}
{{{
>>> Book.objects.filter(Q(foo__name='Alex') | Q(bar__name='Alex'))
<QuerySet [<Book: Book object (1)>, <Book: Book object (2)>, <Book: Book
object (3)>]>
}}}
Django switched to using LEFT OUTER JOIN in this case. Should this same
logic apply to ForeignKeys where `db_constraint=False`?
--
Ticket URL: <https://code.djangoproject.com/ticket/33838#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 on the web visit
https://groups.google.com/d/msgid/django-updates/01070181ee6c0ac1-b0bf8bfd-131d-4aec-a2c6-3ce7ca8663db-000000%40eu-central-1.amazonses.com.