Fixed #11381 -- `GeoManager` + `select_related` + nullable `ForeignKey` now works correctly. Thanks, bretthoerner for ticket and dgouldin for initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11123 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2009-06-29 16:31:21 +00:00
parent 735309341e
commit fdcc0c774a
3 changed files with 9 additions and 2 deletions

View File

@ -225,7 +225,7 @@ class GeoQuery(sql.Query):
values.append(self.convert_values(value, field))
else:
values.extend(row[index_start:])
return values
return tuple(values)
def convert_values(self, value, field):
"""

View File

@ -40,5 +40,5 @@ class Author(models.Model):
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, related_name='books')
author = models.ForeignKey(Author, related_name='books', null=True)
objects = models.GeoManager()

View File

@ -257,6 +257,13 @@ class RelatedGeoModelTest(unittest.TestCase):
self.assertEqual(1, len(qs))
self.assertEqual(3, qs[0].num_books)
def test13_select_related_null_fk(self):
"Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
no_author = Book.objects.create(title='Without Author')
b = Book.objects.select_related('author').get(title='Without Author')
# Should be `None`, and not a 'dummy' model.
self.assertEqual(None, b.author)
# TODO: Related tests for KML, GML, and distance lookups.
def suite():