| | 1679 | If you are filtering across multiple relationships and one of the intermediate |
|---|
| | 1680 | models doesn't have a value that meets the filter condition, Django will treat |
|---|
| | 1681 | it as if there is an empty (all values are ``NULL``), but valid, object there. |
|---|
| | 1682 | All this means is that no error will be raised. For example, in this filter:: |
|---|
| | 1683 | |
|---|
| | 1684 | Blog.objects.filter(entry__author__name='Lennon') |
|---|
| | 1685 | |
|---|
| | 1686 | (if there was a related ``Author`` model), if there was no ``author`` |
|---|
| | 1687 | associated with an entry, it would be treated as if there was also no ``name`` |
|---|
| | 1688 | attached, rather than raising an error because of the missing ``author``. |
|---|
| | 1689 | Usually this is exactly what you want to have happen. The only case where it |
|---|
| | 1690 | might be confusing is if you are using ``isnull``. Thus:: |
|---|
| | 1691 | |
|---|
| | 1692 | Blog.objects.filter(entry__author__name__isnull=True) |
|---|
| | 1693 | |
|---|
| | 1694 | will return ``Blog`` objects that have an empty ``name`` on the ``author`` and |
|---|
| | 1695 | also those which have an empty ``author`` on the ``entry``. If you don't want |
|---|
| | 1696 | those latter objects, you could write:: |
|---|
| | 1697 | |
|---|
| | 1698 | Blog.objetcs.filter(entry__author__isnull=False, |
|---|
| | 1699 | entry__author__name__isnull=True) |
|---|
| | 1700 | |
|---|