mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #20946 -- model inheritance + m2m failure
Cleaned up the internal implementation of m2m fields by removing related.py _get_fk_val(). The _get_fk_val() was doing the wrong thing if asked for the foreign key value on foreign key to parent model's primary key when child model had different primary key field.
This commit is contained in:
@@ -10,7 +10,8 @@ from django.utils import six
|
||||
|
||||
from .models import (
|
||||
Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post,
|
||||
Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel)
|
||||
Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel,
|
||||
Title, Base, SubBase)
|
||||
|
||||
|
||||
class ModelInheritanceTests(TestCase):
|
||||
@@ -357,3 +358,16 @@ class ModelInheritanceTests(TestCase):
|
||||
[Place.objects.get(pk=s.pk)],
|
||||
lambda x: x
|
||||
)
|
||||
|
||||
def test_custompk_m2m(self):
|
||||
b = Base.objects.create()
|
||||
b.titles.add(Title.objects.create(title="foof"))
|
||||
s = SubBase.objects.create(sub_id=b.id)
|
||||
b = Base.objects.get(pk=s.id)
|
||||
self.assertNotEqual(b.pk, s.pk)
|
||||
# Low-level test for related_val
|
||||
self.assertEqual(s.titles.related_val, (s.id,))
|
||||
# Higher level test for correct query values (title foof not
|
||||
# accidentally found).
|
||||
self.assertQuerysetEqual(
|
||||
s.titles.all(), [])
|
||||
|
||||
Reference in New Issue
Block a user