Add a safety note on using the new delete rules.
This commit is contained in:
parent
0f68df3b4a
commit
03a757bc6e
@ -193,6 +193,7 @@ as the constructor's argument::
|
|||||||
class ProfilePage(Document):
|
class ProfilePage(Document):
|
||||||
content = StringField()
|
content = StringField()
|
||||||
|
|
||||||
|
|
||||||
Dealing with deletion of referred documents
|
Dealing with deletion of referred documents
|
||||||
'''''''''''''''''''''''''''''''''''''''''''
|
'''''''''''''''''''''''''''''''''''''''''''
|
||||||
By default, MongoDB doesn't check the integrity of your data, so deleting
|
By default, MongoDB doesn't check the integrity of your data, so deleting
|
||||||
@ -207,6 +208,11 @@ supplying the :attr:`reverse_delete_rule` attributes on the
|
|||||||
...
|
...
|
||||||
profile_page = ReferenceField('ProfilePage', reverse_delete_rule=mongoengine.NULLIFY)
|
profile_page = ReferenceField('ProfilePage', reverse_delete_rule=mongoengine.NULLIFY)
|
||||||
|
|
||||||
|
The declaration in this example means that when an :class:`Employee` object is
|
||||||
|
removed, the :class:`ProfilePage` that belongs to that employee is removed as
|
||||||
|
well. If a whole batch of employees is removed, all profile pages that are
|
||||||
|
linked are removed as well.
|
||||||
|
|
||||||
Its value can take any of the following constants:
|
Its value can take any of the following constants:
|
||||||
|
|
||||||
:const:`mongoengine.DO_NOTHING`
|
:const:`mongoengine.DO_NOTHING`
|
||||||
@ -223,6 +229,23 @@ Its value can take any of the following constants:
|
|||||||
are deleted first.
|
are deleted first.
|
||||||
|
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
A safety note on setting up these delete rules! Since the delete rules are
|
||||||
|
not recorded on the database level by MongoDB itself, but instead at runtime,
|
||||||
|
in-memory, by the MongoEngine module, it is of the upmost importance
|
||||||
|
that the module that declares the relationship is loaded **BEFORE** the
|
||||||
|
delete is invoked.
|
||||||
|
|
||||||
|
If, for example, the :class:`Employee` object lives in the
|
||||||
|
:mod:`payroll` app, and the :class:`ProfilePage` in the :mod:`people`
|
||||||
|
app, it is extremely important that the :mod:`people` app is loaded
|
||||||
|
before any employee is removed, because otherwise, MongoEngine could
|
||||||
|
never know this relationship exists.
|
||||||
|
|
||||||
|
In Django, be sure to put all apps that have such delete rule declarations in
|
||||||
|
their :file:`models.py` in the :const:`INSTALLED_APPS` tuple.
|
||||||
|
|
||||||
|
|
||||||
Generic reference fields
|
Generic reference fields
|
||||||
''''''''''''''''''''''''
|
''''''''''''''''''''''''
|
||||||
A second kind of reference field also exists,
|
A second kind of reference field also exists,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user