Changeset 9007
- Timestamp:
- 09/10/08 21:00:27 (4 months ago)
- Files:
-
- django/trunk/django/db/models/sql/query.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/queries/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/sql/query.py
r8898 r9007 293 293 result.append('GROUP BY %s' % ', '.join(grouping)) 294 294 295 if self.having: 296 having, h_params = self.get_having() 297 result.append('HAVING %s' % ', '.join(having)) 298 params.extend(h_params) 299 295 300 if ordering: 296 301 result.append('ORDER BY %s' % ', '.join(ordering)) … … 573 578 result.append(str(col)) 574 579 return result 580 581 def get_having(self): 582 """ 583 Returns a tuple representing the SQL elements in the "having" clause. 584 By default, the elements of self.having have their as_sql() method 585 called or are returned unchanged (if they don't have an as_sql() 586 method). 587 """ 588 result = [] 589 params = [] 590 for elt in self.having: 591 if hasattr(elt, 'as_sql'): 592 sql, params = elt.as_sql() 593 result.append(sql) 594 params.extend(params) 595 else: 596 result.append(elt) 597 return result, params 575 598 576 599 def get_ordering(self): django/trunk/tests/regressiontests/queries/models.py
r8832 r9007 954 954 1 955 955 956 A check to ensure we don't break the internal query construction of GROUP BY 957 and HAVING. These aren't supported in the public API, but the Query class knows 958 about them and shouldn't do bad things. 959 >>> qs = Tag.objects.values_list('parent_id', flat=True).order_by() 960 >>> qs.query.group_by = ['parent_id'] 961 >>> qs.query.having = ['count(parent_id) > 1'] 962 >>> expected = [t3.parent_id, t4.parent_id] 963 >>> expected.sort() 964 >>> result = list(qs) 965 >>> result.sort() 966 >>> expected == result 967 True 968 956 969 """} 957 970
