Ticket #13263: 13263_docs_patch.diff
File 13263_docs_patch.diff, 1.7 KB (added by , 15 years ago) |
---|
-
docs/topics/db/queries.txt
419 419 it as if there is an empty (all values are ``NULL``), but valid, object there. 420 420 All this means is that no error will be raised. For example, in this filter:: 421 421 422 Blog.objects.filter(entry__author __name='Lennon')422 Blog.objects.filter(entry__authors__name='Lennon') 423 423 424 424 (if there was a related ``Author`` model), if there was no ``author`` 425 425 associated with an entry, it would be treated as if there was also no ``name`` … … 427 427 Usually this is exactly what you want to have happen. The only case where it 428 428 might be confusing is if you are using ``isnull``. Thus:: 429 429 430 Blog.objects.filter(entry__author __name__isnull=True)430 Blog.objects.filter(entry__authors__name__isnull=True) 431 431 432 432 will return ``Blog`` objects that have an empty ``name`` on the ``author`` and 433 433 also those which have an empty ``author`` on the ``entry``. If you don't want 434 434 those latter objects, you could write:: 435 435 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) 438 438 439 439 Spanning multi-valued relationships 440 440 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 532 532 the entries where the author's name is the same as the blog name, we could 533 533 issue the query: 534 534 535 >>> Entry.objects.filter(author __name=F('blog__name'))535 >>> Entry.objects.filter(authors__name=F('blog__name')) 536 536 537 537 The pk lookup shortcut 538 538 ----------------------