summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorMarcelo Galigniana <marcelogaligniana@gmail.com>2023-02-07 04:04:23 -0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-07 08:05:17 +0100
commit9306a8d18fb155519389bb79a34a35ba578e21ec (patch)
tree187b916149014d1aa5c90106ad46020153a95487 /docs/topics
parentd70b2a88e8f1300c1564eb9e12822d5bf65ecaf0 (diff)
[4.2.x] Fixed #34310 -- Added deletion example to one-to-one topic.
Backport of 7c6195ef81075b03a704431b5d08ec597e8573f7 from main
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/examples/one_to_one.txt10
1 files changed, 10 insertions, 0 deletions
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")
<Place: Demon Dogs the place>
+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()
+ <QuerySet [<Restaurant: Demon Dogs the restaurant>]>
+
Add a Waiter to the Restaurant::
>>> w = r.waiter_set.create(name='Joe')