Django

Code

Changeset 8141

Show
Ignore:
Timestamp:
07/29/08 18:09:54 (5 months ago)
Author:
mtredinnick
Message:

Added a clarification to the docs about filtering across nullable intermediate
models with a NULL entry. I'm not brilliantly happy with the description
(it's too long for such an edge case, for a start), but it gets the intent across. Refs #8025.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/db-api.txt

    r8072 r8141  
    16771677    Blog.objects.filter(entry__headline__contains='Lennon') 
    16781678 
     1679If you are filtering across multiple relationships and one of the intermediate 
     1680models doesn't have a value that meets the filter condition, Django will treat 
     1681it as if there is an empty (all values are ``NULL``), but valid, object there. 
     1682All 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`` 
     1687associated with an entry, it would be treated as if there was also no ``name`` 
     1688attached, rather than raising an error because of the missing ``author``. 
     1689Usually this is exactly what you want to have happen. The only case where it 
     1690might be confusing is if you are using ``isnull``. Thus:: 
     1691 
     1692    Blog.objects.filter(entry__author__name__isnull=True) 
     1693 
     1694will return ``Blog`` objects that have an empty ``name`` on the ``author`` and 
     1695also those which have an empty ``author`` on the ``entry``. If you don't want 
     1696those latter objects, you could write:: 
     1697 
     1698    Blog.objetcs.filter(entry__author__isnull=False, 
     1699            entry__author__name__isnull=True) 
     1700 
    16791701Spanning multi-valued relationships 
    16801702~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~