Django

Code

Ticket #4957 (closed: duplicate)

Opened 1 year ago

Last modified 10 months ago

Query for ForeignKey using implicit exact and to_field breaks

Reported by: jdunck Assigned to: nobody
Milestone: Component: Database wrapper
Version: SVN Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

09/13/07 16:44:05 changed by mtredinnick

  • keywords set to qs-rf-fixed.
  • component changed from Core framework to Database wrapper.
  • stage changed from Unreviewed to Accepted.

09/16/07 15:20:16 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #4088.


Add/Change #4957 (Query for ForeignKey using implicit exact and to_field breaks)




Change Properties
Action