Opened 3 hours ago
#36188 new Bug
Reverse lookups on OneToOneField not working?
Reported by: | Willem Van Onsem | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This StackOverflow post shows a scenario where a OneToOneField
is filtered on top of another OneToOneField
. So for example with the following modeling:
class Switch(models.Model): fqdn = models.CharField(max_length=45, unique=True) class ConfigState(models.Model): switch = models.OneToOneField(Switch, models.CASCADE, db_column='switch', primary_key=True, related_name='config_state') class EdgeSwitch(models.Model): switch = models.OneToOneField(Switch, models.CASCADE, db_column='switch', primary_key=True, related_name='edge_switch')
The query EdgeSwitch.objects.filter(switch__config_state=1)
does (no longer) work. On Django-3.x it apparently worked.
Note:
See TracTickets
for help on using tickets.