Opened 11 years ago

Closed 11 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: master
Severity: Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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]

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 =

I'll try to work up a patch for it. Tired now.

Change History (2)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Component: Core frameworkDatabase wrapper
Keywords: qs-rf-fixed added
Triage Stage: UnreviewedAccepted

comment:2 Changed 11 years ago by James Bennett

Resolution: duplicate
Status: newclosed

Duplicate of #4088.

Note: See TracTickets for help on using tickets.
Back to Top