Ticket #7231: extra-join-1.2.patch

File extra-join-1.2.patch, 3.3 KB (added by jonozzz, 14 years ago)

adapted for the 1.2 release

  • django/db/models/query.py

    diff -ruw Django-1.2.1.orig/django/db/models/query.py Django-1.2.1/django/db/models/query.py
    old new  
    653653        return obj
    654654
    655655    def extra(self, select=None, where=None, params=None, tables=None,
    656               order_by=None, select_params=None):
     656              order_by=None, select_params=None, join=None):
    657657        """
    658658        Adds extra SQL fragments to the query.
    659659        """
    660660        assert self.query.can_filter(), \
    661661                "Cannot change a query once a slice has been taken"
    662662        clone = self._clone()
    663         clone.query.add_extra(select, select_params, where, params, tables, order_by)
     663        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
    664664        return clone
    665665
    666666    def reverse(self):
  • django/db/models/sql/compiler.py

    diff -ruw Django-1.2.1.orig/django/db/models/sql/compiler.py Django-1.2.1/django/db/models/sql/compiler.py
    old new  
    7777        result.extend(from_)
    7878        params.extend(f_params)
    7979
     80        if self.query.extra_join:
     81            result.append(' '.join(self.query.extra_join))
     82
    8083        if where:
    8184            result.append('WHERE %s' % where)
    8285            params.extend(w_params)
  • django/db/models/sql/query.py

    diff -ruw Django-1.2.1.orig/django/db/models/sql/query.py Django-1.2.1/django/db/models/sql/query.py
    old new  
    151151
    152152        self.extra_tables = ()
    153153        self.extra_order_by = ()
     154        self.extra_join = ()
    154155
    155156        # A tuple that is a set of model field names and either True, if these
    156157        # are the fields to defer, or False if these are the only fields to
     
    284285            obj._extra_select_cache = self._extra_select_cache.copy()
    285286        obj.extra_tables = self.extra_tables
    286287        obj.extra_order_by = self.extra_order_by
     288        obj.extra_join = self.extra_join
    287289        obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo)
    288290        if self.filter_is_sticky and self.used_aliases:
    289291            obj.used_aliases = self.used_aliases.copy()
     
    404406
    405407    def has_results(self, using):
    406408        q = self.clone()
    407         q.add_extra({'a': 1}, None, None, None, None, None)
     409        q.add_extra({'a': 1}, None, None, None, None, None, None)
    408410        q.select = []
    409411        q.select_fields = []
    410412        q.default_cols = False
     
    16091611        self.related_select_cols = []
    16101612        self.related_select_fields = []
    16111613
    1612     def add_extra(self, select, select_params, where, params, tables, order_by):
     1614    def add_extra(self, select, select_params, where, params, tables, order_by, join):
    16131615        """
    16141616        Adds data to the various extra_* attributes for user-created additions
    16151617        to the query.
     
    16401642            self.extra_tables += tuple(tables)
    16411643        if order_by:
    16421644            self.extra_order_by = order_by
     1645        if join:
     1646            self.extra_join += tuple(join)
    16431647
    16441648    def clear_deferred_loading(self):
    16451649        """
Back to Top