mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #13003 -- Ensured that ._state.db is set correctly for select_related() queries. Thanks to Alex Gaynor for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3508a86ddf
commit
18983f0ee7
2 changed files with 29 additions and 9 deletions
|
@ -641,6 +641,20 @@ class QueryTestCase(TestCase):
|
|||
val = Book.objects.raw('SELECT id FROM "multiple_database_book"').using('other')
|
||||
self.assertEqual(map(lambda o: o.pk, val), [dive.pk])
|
||||
|
||||
def test_select_related(self):
|
||||
"Database assignment is retained if an object is retrieved with select_related()"
|
||||
# Create a book and author on the other database
|
||||
mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||
dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
published=datetime.date(2009, 5, 4),
|
||||
editor=mark)
|
||||
|
||||
# Retrieve the Person using select_related()
|
||||
book = Book.objects.using('other').select_related('editor').get(title="Dive into Python")
|
||||
|
||||
# The editor instance should have a db state
|
||||
self.assertEqual(book.editor._state.db, 'other')
|
||||
|
||||
class TestRouter(object):
|
||||
# A test router. The behaviour is vaguely master/slave, but the
|
||||
# databases aren't assumed to propagate changes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue