summaryrefslogtreecommitdiff
path: root/tests/many_to_one
diff options
context:
space:
mode:
authorRob <tienrobertnguyenn@gmail.com>2019-05-20 22:04:26 +1000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-21 10:08:09 +0200
commit266e7e0eccf1d109e8c64c7bc5e612a538ad618a (patch)
tree20c9eeec63c2af04a1d36186081e716620275e6b /tests/many_to_one
parent9d6f981a66bd2c4188c4a3e08e4f36fc9c4882ef (diff)
downloaddjango-266e7e0eccf1d109e8c64c7bc5e612a538ad618a.tar.gz
Refs #28147 -- Added test for saving nullable ForeignKey with to_field attribute after saving parent.
Diffstat (limited to 'tests/many_to_one')
-rw-r--r--tests/many_to_one/tests.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index 28430256dc..8ad467b6b6 100644
--- a/tests/many_to_one/tests.py
+++ b/tests/many_to_one/tests.py
@@ -522,6 +522,15 @@ class ManyToOneTests(TestCase):
self.assertIsNot(c.parent, p)
self.assertEqual(c.parent, p)
+ def test_save_nullable_fk_after_parent_with_to_field(self):
+ parent = Parent(name='jeff')
+ child = ToFieldChild(parent=parent)
+ parent.save()
+ child.save()
+ child.refresh_from_db()
+ self.assertEqual(child.parent, parent)
+ self.assertEqual(child.parent_id, parent.name)
+
def test_fk_to_bigautofield(self):
ch = City.objects.create(name='Chicago')
District.objects.create(city=ch, name='Far South')