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
|
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}
Closed in r10434