Ticket #25672: 25672Docs.diff

File 25672Docs.diff, 1.4 KB (added by Benjamin Phillips, 9 years ago)
  • docs/topics/db/models.txt

    diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
    index 28bbf89..74986d8 100644
    a b The only way to create this type of relationship is to create instances of the  
    529529intermediate model.
    530530
    531531The :meth:`~django.db.models.fields.related.RelatedManager.remove` method is
    532 disabled for similar reasons. However, the
    533 :meth:`~django.db.models.fields.related.RelatedManager.clear` method can be
    534 used to remove all many-to-many relationships for an instance::
     532disabled for similar reasons. If the custom through-table defined by the
     533intermediate model does not enforce uniqueness on the ``(model1, model2)`` pair,
     534a ``remove`` call will not provide enough information as to which intermediate
     535model instance should be deleted::
     536
     537    >>> m3 = Membership(person=ringo, group=beatles,
     538    ...     date_joined=date(1968, 9, 4),
     539    ...     invite_reason="You've been gone for a month and we miss you")
     540    >>> beatles.members.all()
     541    <QuerySet [<Person: Ringo Starr>, <Person: Paul McCartney>,
     542    <Person: Ringo Starr>]>
     543    # THIS WILL NOT WORK BECAUSE IT CANNOT TELL WHICH MEMBERSHIP TO REMOVE
     544    >>> beatles.members.remove(ringo)
     545
     546However, the :meth:`~django.db.models.fields.related.RelatedManager.clear`
     547method can be used to remove all many-to-many relationships for an instance::
    535548
    536549    >>> # Beatles have broken up
    537550    >>> beatles.members.clear()
Back to Top