diff --git a/en/orm/query-builder.rst b/en/orm/query-builder.rst index bb1f52c89f..27b3484c1f 100644 --- a/en/orm/query-builder.rst +++ b/en/orm/query-builder.rst @@ -247,6 +247,18 @@ method:: $query = $articles->find() ->order(['title' => 'ASC', 'id' => 'ASC']); + +When calling ``order()`` multiple times on a query multiple clauses will be appended. +However, when using finders you may sometimes need to overwrite the ``ORDER BY``. +Set the second parameter of ``order()`` (as well as ``orderAsc()`` or ``orderDesc()``) to +``Query::OVERWRITE`` or to ``true``:: + + $query = $articles->find() + ->order(['title' => 'ASC']); + // Later, overwrite the ORDER BY clause instead of appending to it. + $query = $articles->find() + ->order(['created' => 'DESC'], Query::OVERWRITE); + .. versionadded:: 3.0.12 In addition to ``order``, the ``orderAsc`` and ``orderDesc`` methods can be