diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-06-17 15:53:07 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-06-17 15:53:07 -0400 |
| commit | 0276ec0cd874aafb06606c443e8cdeb692c232f9 (patch) | |
| tree | 4774fbc3c83baec5ff2b2a2d164d61da65f30886 /lib/sqlalchemy | |
| parent | caa465512cae22d2a5288ff7b424904d246459fa (diff) | |
| download | sqlalchemy-0276ec0cd874aafb06606c443e8cdeb692c232f9.tar.gz | |
- query.order_by() now accepts False, which cancels
any existing order_by() state on the Query, allowing
subsequent generative methods to be called which do
not support ORDER BY. This is not the same as the
already existing feature of passing None, which
suppresses any existing order_by() settings, including
those configured on the mapper. False will make it
as though order_by() was never called, while
None is an active setting.
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 50be13088..6b36b370a 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -854,17 +854,34 @@ class Query(object): @util.accepts_a_list_as_starargs(list_deprecation='deprecated') def order_by(self, *criterion): """apply one or more ORDER BY criterion to the query and return - the newly resulting ``Query``""" + the newly resulting ``Query`` + + All existing ORDER BY settings can be suppressed by + passing ``None`` - this will suppress any ORDER BY configured + on mappers as well. + + Alternatively, an existing ORDER BY setting on the Query + object can be entirely cancelled by passing ``False`` + as the value - use this before calling methods where + an ORDER BY is invalid. + + """ - if len(criterion) == 1 and criterion[0] is None: - self._order_by = None - else: - criterion = self._adapt_col_list(criterion) + if len(criterion) == 1: + if criterion[0] is False: + if '_order_by' in self.__dict__: + del self._order_by + return + if criterion[0] is None: + self._order_by = None + return + + criterion = self._adapt_col_list(criterion) - if self._order_by is False or self._order_by is None: - self._order_by = criterion - else: - self._order_by = self._order_by + criterion + if self._order_by is False or self._order_by is None: + self._order_by = criterion + else: + self._order_by = self._order_by + criterion @_generative(_no_statement_condition, _no_limit_offset) @util.accepts_a_list_as_starargs(list_deprecation='deprecated') |
