summaryrefslogtreecommitdiff
path: root/docs/topics/db
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-07-24 07:51:40 -0400
committerTim Graham <timograham@gmail.com>2015-08-10 08:51:32 -0400
commit5980b05c1fad69eef907e0076aa2dc837edab529 (patch)
tree559858b70445d26700fcf6ef09c655d2fa050557 /docs/topics/db
parent12f91f6ebdd2470197fff4e053b50f3e54294028 (diff)
Fixed #25160 -- Moved unsaved model instance data loss check to Model.save()
This mostly reverts 5643a3b51be338196d0b292d5626ad43648448d3 and 81e1a35c364e5353d2bf99368ad30a4184fbb653. Thanks Carl Meyer for review.
Diffstat (limited to 'docs/topics/db')
-rw-r--r--docs/topics/db/examples/many_to_one.txt16
-rw-r--r--docs/topics/db/examples/one_to_one.txt20
2 files changed, 14 insertions, 22 deletions
diff --git a/docs/topics/db/examples/many_to_one.txt b/docs/topics/db/examples/many_to_one.txt
index 10020a83cb..efa5c37f3b 100644
--- a/docs/topics/db/examples/many_to_one.txt
+++ b/docs/topics/db/examples/many_to_one.txt
@@ -55,19 +55,17 @@ relationship. For example, creating an ``Article`` with unsaved ``Reporter``
raises ``ValueError``::
>>> r3 = Reporter(first_name='John', last_name='Smith', email='john@example.com')
- >>> Article(headline="This is a test", pub_date=date(2005, 7, 27), reporter=r3)
+ >>> Article.objects.create(headline="This is a test", pub_date=date(2005, 7, 27), reporter=r3)
Traceback (most recent call last):
...
- ValueError: 'Cannot assign "<Reporter: John Smith>": "Reporter" instance isn't saved in the database.'
+ ValueError: save() prohibited to prevent data loss due to unsaved related object 'reporter'.
-If you want to disable the unsaved instance check, you can use the
-:attr:`~django.db.models.ForeignKey.allow_unsaved_instance_assignment`
-attribute.
+.. versionchanged:: 1.8.4
-.. versionchanged:: 1.8
-
- Previously, assigning unsaved objects did not raise an error and could
- result in silent data loss.
+ Previously, saving an object with unsaved related objects did not raise an
+ error and could result in silent data loss. In 1.8-1.8.3, unsaved model
+ instances couldn't be assigned to related fields, but this restriction was
+ removed to allow easier usage of in-memory models.
Article objects have access to their related Reporter objects::
diff --git a/docs/topics/db/examples/one_to_one.txt b/docs/topics/db/examples/one_to_one.txt
index 311ff75d8d..97c5b5c4b1 100644
--- a/docs/topics/db/examples/one_to_one.txt
+++ b/docs/topics/db/examples/one_to_one.txt
@@ -96,23 +96,17 @@ relationship. For example, creating an ``Restaurant`` with unsaved ``Place``
raises ``ValueError``::
>>> p3 = Place(name='Demon Dogs', address='944 W. Fullerton')
- >>> Restaurant(place=p3, serves_hot_dogs=True, serves_pizza=False)
+ >>> Restaurant.objects.create(place=p3, serves_hot_dogs=True, serves_pizza=False)
Traceback (most recent call last):
...
- ValueError: 'Cannot assign "<Place: Demon Dogs>": "Place" instance isn't saved in the database.'
- >>> p.restaurant = Restaurant(place=p, serves_hot_dogs=True, serves_pizza=False)
- Traceback (most recent call last):
- ...
- ValueError: 'Cannot assign "<Restaurant: Demon Dogs the restaurant>": "Restaurant" instance isn't saved in the database.'
-
-If you want to disable the unsaved instance check, you can use the
-:attr:`~django.db.models.ForeignKey.allow_unsaved_instance_assignment`
-attribute.
+ ValueError: save() prohibited to prevent data loss due to unsaved related object 'place'.
-.. versionchanged:: 1.8
+.. versionchanged:: 1.8.4
- Previously, assigning unsaved objects did not raise an error and could
- result in silent data loss.
+ Previously, saving an object with unsaved related objects did not raise an
+ error and could result in silent data loss. In 1.8-1.8.3, unsaved model
+ instances couldn't be assigned to related fields, but this restriction was
+ removed to allow easier usage of in-memory models.
Restaurant.objects.all() just returns the Restaurants, not the Places. Note
that there are two restaurants - Ace Hardware the Restaurant was created in the