MCPcopy
hub / github.com/django/django / test_fk_to_m2m_through

Method test_fk_to_m2m_through

tests/delete_regress/tests.py:100–117  ·  view source on GitHub ↗

If an M2M relationship has an explicitly-specified through model, and some other model has an FK to that through model, deletion is cascaded from one of the participants in the M2M, to the through model, to its related model.

(self)

Source from the content-addressed store, hash-verified

98 self.assertEqual(AwardNote.objects.count(), 0)
99
100 def test_fk_to_m2m_through(self):
101 """
102 If an M2M relationship has an explicitly-specified through model, and
103 some other model has an FK to that through model, deletion is cascaded
104 from one of the participants in the M2M, to the through model, to its
105 related model.
106 """
107 juan = Child.objects.create(name="Juan")
108 paints = Toy.objects.create(name="Paints")
109 played = PlayedWith.objects.create(
110 child=juan, toy=paints, date=datetime.date.today()
111 )
112 PlayedWithNote.objects.create(played=played, note="the next Jackson Pollock")
113 self.assertEqual(PlayedWithNote.objects.count(), 1)
114 paints.delete()
115 self.assertEqual(PlayedWith.objects.count(), 0)
116 # first two asserts just sanity checks, this is the kicker:
117 self.assertEqual(PlayedWithNote.objects.count(), 0)
118
119 def test_15776(self):
120 policy = Policy.objects.create(pk=1, policy_number="1234")

Callers

nothing calls this directly

Calls 3

createMethod · 0.45
countMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected