From 7c6195ef81075b03a704431b5d08ec597e8573f7 Mon Sep 17 00:00:00 2001 From: Marcelo Galigniana Date: Tue, 7 Feb 2023 04:04:23 -0300 Subject: [PATCH] Fixed #34310 -- Added deletion example to one-to-one topic. --- docs/topics/db/examples/one_to_one.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/topics/db/examples/one_to_one.txt b/docs/topics/db/examples/one_to_one.txt index a1a238d0f2..92f5e9ce40 100644 --- a/docs/topics/db/examples/one_to_one.txt +++ b/docs/topics/db/examples/one_to_one.txt @@ -137,6 +137,16 @@ This also works in reverse:: >>> Place.objects.get(restaurant__place__name__startswith="Demon") +If you delete a place, its restaurant will be deleted (assuming that the +``OneToOneField`` was defined with +:attr:`~django.db.models.ForeignKey.on_delete` set to ``CASCADE``, which is the +default):: + + >>> p2.delete() + (2, {'one_to_one.Restaurant': 1, 'one_to_one.Place': 1}) + >>> Restaurant.objects.all() + ]> + Add a Waiter to the Restaurant:: >>> w = r.waiter_set.create(name='Joe')