Ticket #13263: 13263_docs_patch.diff

File 13263_docs_patch.diff, 1.7 KB (added by Gabriel Hurley, 15 years ago)

corrects name of m2m field in query doc examples

  • docs/topics/db/queries.txt

     
    419419it as if there is an empty (all values are ``NULL``), but valid, object there.
    420420All this means is that no error will be raised. For example, in this filter::
    421421
    422     Blog.objects.filter(entry__author__name='Lennon')
     422    Blog.objects.filter(entry__authors__name='Lennon')
    423423
    424424(if there was a related ``Author`` model), if there was no ``author``
    425425associated with an entry, it would be treated as if there was also no ``name``
     
    427427Usually this is exactly what you want to have happen. The only case where it
    428428might be confusing is if you are using ``isnull``. Thus::
    429429
    430     Blog.objects.filter(entry__author__name__isnull=True)
     430    Blog.objects.filter(entry__authors__name__isnull=True)
    431431
    432432will return ``Blog`` objects that have an empty ``name`` on the ``author`` and
    433433also those which have an empty ``author`` on the ``entry``. If you don't want
    434434those latter objects, you could write::
    435435
    436     Blog.objects.filter(entry__author__isnull=False,
    437             entry__author__name__isnull=True)
     436    Blog.objects.filter(entry__authors__isnull=False,
     437            entry__authors__name__isnull=True)
    438438
    439439Spanning multi-valued relationships
    440440~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    532532the entries where the author's name is the same as the blog name, we could
    533533issue the query:
    534534
    535     >>> Entry.objects.filter(author__name=F('blog__name'))
     535    >>> Entry.objects.filter(authors__name=F('blog__name'))
    536536
    537537The pk lookup shortcut
    538538----------------------
Back to Top