Ticket #9961: select_related.patch

File select_related.patch, 2.0 KB (added by rdaysky, 7 years ago)
  • django/db/models/query.py

    diff -urNad django/db/models/query.py django/db/models/query.py
     
    525525        If fields are specified, they must be ForeignKey fields and only those
    526526        related objects are included in the selection.
    527527        """
    528         depth = kwargs.pop('depth', 0)
     528        depth = kwargs.pop('depth', None)
    529529        if kwargs:
    530530            raise TypeError('Unexpected keyword arguments to select_related: %s'
    531531                    % (kwargs.keys(),))
     
    536536            obj.query.add_select_related(fields)
    537537        else:
    538538            obj.query.select_related = True
    539         if depth:
     539        if depth is not None:
    540540            obj.query.max_depth = depth
    541541        return obj
    542542
     
    781781        yield iter([]).next()
    782782
    783783
    784 def get_cached_row(klass, row, index_start, max_depth=0, cur_depth=0,
     784def get_cached_row(klass, row, index_start, max_depth=None, cur_depth=0,
    785785                   requested=None):
    786786    """
    787787    Helper function that recursively returns an object with the specified
    788788    related attributes already populated.
    789789    """
    790     if max_depth and requested is None and cur_depth > max_depth:
     790    if max_depth is not None and requested is None and cur_depth > max_depth:
    791791        # We've recursed deeply enough; stop now.
    792792        return None
    793793
  • django/db/models/sql/query.py

    diff -urNad django/db/models/sql/query.py django/db/models/sql/query.py
     
    953953        (for example, cur_depth=1 means we are looking at models with direct
    954954        connections to the root model).
    955955        """
    956         if not restricted and self.max_depth and cur_depth > self.max_depth:
     956        if not restricted and self.max_depth is not None and cur_depth > self.max_depth:
    957957            # We've recursed far enough; bail out.
    958958            return
    959959
Back to Top