summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-03-14 21:25:33 -0400
committerLoïc Bistuer <loic.bistuer@gmail.com>2015-07-28 09:28:25 +0700
commitadc0c4fbac98f9cb975e8fa8220323b2de638b46 (patch)
tree6d00b444423b09a764fa3eb7d5b9f278c6531c0e /docs/ref
parentc2e70f02653519db3a49cd48f5158ccad7434d25 (diff)
Fixed #18556 -- Allowed RelatedManager.add() to execute 1 query where possible.
Thanks Loic Bistuer for review.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/models/relations.txt20
1 files changed, 17 insertions, 3 deletions
diff --git a/docs/ref/models/relations.txt b/docs/ref/models/relations.txt
index 9e27e27151..d480ec18c2 100644
--- a/docs/ref/models/relations.txt
+++ b/docs/ref/models/relations.txt
@@ -36,7 +36,7 @@ Related objects reference
In this example, the methods below will be available both on
``topping.pizza_set`` and on ``pizza.toppings``.
- .. method:: add(*objs)
+ .. method:: add(*objs, bulk=True)
Adds the specified model objects to the related object set.
@@ -48,7 +48,13 @@ Related objects reference
In the example above, in the case of a
:class:`~django.db.models.ForeignKey` relationship,
- ``e.save()`` is called by the related manager to perform the update.
+ :meth:`QuerySet.update() <django.db.models.query.QuerySet.update>`
+ is used to perform the update. This requires the objects to already be
+ saved.
+
+ You can use the ``bulk=False`` argument to instead have the related
+ manager perform the update by calling ``e.save()``.
+
Using ``add()`` with a many-to-many relationship, however, will not
call any ``save()`` methods, but rather create the relationships
using :meth:`QuerySet.bulk_create()
@@ -56,6 +62,12 @@ Related objects reference
some custom logic when a relationship is created, listen to the
:data:`~django.db.models.signals.m2m_changed` signal.
+ .. versionchanged:: 1.9
+
+ The ``bulk`` parameter was added. In order versions, foreign key
+ updates were always done using ``save()``. Use ``bulk=False`` if
+ you require the old behavior.
+
.. method:: create(**kwargs)
Creates a new object, saves it and puts it in the related object set.
@@ -135,7 +147,7 @@ Related objects reference
:class:`~django.db.models.ForeignKey`\s where ``null=True`` and it also
accepts the ``bulk`` keyword argument.
- .. method:: set(objs, clear=False)
+ .. method:: set(objs, bulk=True, clear=False)
.. versionadded:: 1.9
@@ -150,6 +162,8 @@ Related objects reference
If ``clear=True``, the ``clear()`` method is called instead and the
whole set is added at once.
+ The ``bulk`` argument is passed on to :meth:`add`.
+
Note that since ``set()`` is a compound operation, it is subject to
race conditions. For instance, new objects may be added to the database
in between the call to ``clear()`` and the call to ``add()``.