Opened 17 years ago
Closed 17 years ago
#4957 closed (duplicate)
Query for ForeignKey using implicit exact and to_field breaks
Reported by: | Jeremy Dunck | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | qs-rf-fixed | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given these models:
class District(models.Model, models.GeoMixin): tea_number = models.CharField(maxlength=20, unique=True) class School(models.Model, models.GeoMixin): district = models.ForeignKey(District, to_field='tea_number')
I expect this to work:
a_district = District.objects.all()[0] Schools.objects.filter(district=a_district)
So that a_district's tea_nuumber attribute is used for the criteria against the School table rather than the District's PK.
django.db.models.query.lookup_inner (line 1082) has the bug:
# RelatedObject is from a 1-1 relation, # No need to join; get the pk value from the related object, # and compare using that. column = current_opts.pk.name
I'll try to work up a patch for it. Tired now.
Change History (2)
comment:1 by , 17 years ago
Component: | Core framework → Database wrapper |
---|---|
Keywords: | qs-rf-fixed added |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Duplicate of #4088.