]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
clarify order_by(None) for Core; improve wording
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 29 Oct 2021 21:53:12 +0000 (17:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 29 Oct 2021 21:53:12 +0000 (17:53 -0400)
the order_by(None) convention was documented for orm.Query
but not Core select.

Change-Id: I0c1ad76c3eefba1cb54b1649cfd09169c17e2bba

lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/selectable.py

index 83b2994075f4834121de694b1022734c09ecc475..eab7a3d75a0ad60f652664ec09d5c5a963e70002 100644 (file)
@@ -1799,11 +1799,19 @@ class Query(
     @_generative
     @_assertions(_no_statement_condition, _no_limit_offset)
     def order_by(self, *clauses):
-        """Apply one or more ORDER BY criterion to the query and return
+        """Apply one or more ORDER BY criteria to the query and return
         the newly resulting :class:`_query.Query`.
 
-        All existing ORDER BY settings can be suppressed by  passing
-        ``None``.
+        e.g.::
+
+            q = session.query(Entity).order_by(Entity.id, Entity.name)
+
+        All existing ORDER BY criteria may be cancelled by passing
+        ``None`` by itself.  New ORDER BY criteria may then be added by
+        invoking :meth:`_orm.Query.order_by` again, e.g.::
+
+            # will erase all ORDER BY and ORDER BY new_col alone
+            q = q.order_by(None).order_by(new_col)
 
         .. seealso::
 
index b0aaa5a31bcaa2e23dbf24373a52870f4c6381ea..aed6482972adc4c4ea9b4924a141a6bc3a16940a 100644 (file)
@@ -3781,12 +3781,19 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase):
     @_generative
     def order_by(self, *clauses):
         r"""Return a new selectable with the given list of ORDER BY
-        criterion applied.
+        criteria applied.
 
         e.g.::
 
             stmt = select(table).order_by(table.c.id, table.c.name)
 
+        All existing ORDER BY criteria may be cancelled by passing
+        ``None`` by itself.  New ORDER BY criteria may then be added by
+        invoking :meth:`_sql.Select.order_by` again, e.g.::
+
+            # will erase all ORDER BY and ORDER BY new_col alone
+            stmt = stmt.order_by(None).order_by(new_col)
+
         :param \*clauses: a series of :class:`_expression.ColumnElement`
          constructs
          which will be used to generate an ORDER BY clause.