Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#10757 closed (fixed)

GeoManager.values does not properly select primary keys across relations

Reported by: David Gouldin Owned by: nobody
Component: GIS Version: dev
Severity: Keywords:
Cc: dgouldin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using GeoManager.values to select a primary key from a foreign relation, GeoManager selects the primary key from its model rather than joining to the related model and selecting that model's primary key. See code sample below:

from django.contrib.gis.db import models

class Bar(models.Model):
    bar_field = models.BooleanField()

    objects = models.GeoManager()

class Foo(models.Model):
    foo_field = models.BooleanField()
    bar = models.ForeignKey(Bar)

    objects = models.GeoManager()

# ---

>>> from djtest.models import *

>>> Foo.objects.all().delete()
>>> Bar.objects.all().delete()

>>> b = Bar(id=50, bar_field=True)
>>> b.save()

>>> f = Foo(foo_field=True, bar=b)
>>> f.save()

>>> Foo.objects.values('id', 'bar__id').query.as_sql()
('SELECT "djtest_foo"."id", "djtest_foo"."id" FROM "djtest_foo"', ())

>>> Foo.objects.values('id', 'bar__id')[0]
{'bar__id': 1, 'id': 1}

Attachments (2)

10757.diff (4.4 KB ) - added by David Gouldin 16 years ago.
10757_v2.diff (5.6 KB ) - added by jbronn 16 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Alex Gaynor, 16 years ago

Component: UncategorizedGIS
milestone: 1.1
Triage Stage: UnreviewedAccepted
Version: 1.0SVN

comment:2 by David Gouldin, 16 years ago

Cc: dgouldin@… added
Has patch: set

by David Gouldin, 16 years ago

Attachment: 10757.diff added

by jbronn, 16 years ago

Attachment: 10757_v2.diff added

comment:3 by Alex Gaynor, 16 years ago

Resolution: fixed
Status: newclosed

Closed in r10434

comment:4 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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