Ticket #7231: extra-join-1.1.diff

File extra-join-1.1.diff, 2.6 KB (added by Davide Muzzarelli, 15 years ago)

info@…

  • django/db/models/sql/query.py

     
    9696        self.extra_where = ()
    9797        self.extra_params = ()
    9898        self.extra_order_by = ()
     99        self.extra_join = ()
    99100
    100101        # A tuple that is a set of model field names and either True, if these
    101102        # are the fields to defer, or False if these are the only fields to
     
    236237        obj.extra_where = self.extra_where
    237238        obj.extra_params = self.extra_params
    238239        obj.extra_order_by = self.extra_order_by
     240        obj.extra_join = self.extra_join
    239241        obj.deferred_loading = deepcopy(self.deferred_loading)
    240242        if self.filter_is_sticky and self.used_aliases:
    241243            obj.used_aliases = self.used_aliases.copy()
     
    415417        result.append('FROM')
    416418        result.extend(from_)
    417419        params.extend(f_params)
     420       
     421        if self.extra_join:
     422            result.append(' '.join(self.extra_join))
    418423
    419424        if where:
    420425            result.append('WHERE %s' % where)
     
    21572162        self.related_select_cols = []
    21582163        self.related_select_fields = []
    21592164
    2160     def add_extra(self, select, select_params, where, params, tables, order_by):
     2165    def add_extra(self, select, select_params, where, params, tables, order_by, join):
    21612166        """
    21622167        Adds data to the various extra_* attributes for user-created additions
    21632168        to the query.
     
    21902195            self.extra_tables += tuple(tables)
    21912196        if order_by:
    21922197            self.extra_order_by = order_by
     2198        if join:
     2199            self.extra_join += tuple(join)
    21932200
    21942201    def clear_deferred_loading(self):
    21952202        """
  • django/db/models/query.py

     
    601601        return obj
    602602
    603603    def extra(self, select=None, where=None, params=None, tables=None,
    604               order_by=None, select_params=None):
     604              order_by=None, select_params=None, join=None):
    605605        """
    606606        Adds extra SQL fragments to the query.
    607607        """
    608608        assert self.query.can_filter(), \
    609609                "Cannot change a query once a slice has been taken"
    610610        clone = self._clone()
    611         clone.query.add_extra(select, select_params, where, params, tables, order_by)
     611        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
    612612        return clone
    613613
    614614    def reverse(self):
Back to Top