From 233485ee41e6362b576b0c0d534b2c6e90653ce6 Mon Sep 17 00:00:00 2001 From: inoas Date: Wed, 7 Jun 2017 17:00:17 +0200 Subject: [PATCH 1/2] Overwrite Order By @lorenzo when writing this I thought that there should possibly be Query::PREPEND and Query::APPEND (latter is default behavior) to control Order building... --- en/orm/query-builder.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/en/orm/query-builder.rst b/en/orm/query-builder.rst index bb1f52c89f..51b485489b 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 From 8144203f7d039fca0ac9373b7e94607412829df5 Mon Sep 17 00:00:00 2001 From: inoas Date: Thu, 8 Jun 2017 00:44:41 +0200 Subject: [PATCH 2/2] Update query-builder.rst --- en/orm/query-builder.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/orm/query-builder.rst b/en/orm/query-builder.rst index 51b485489b..27b3484c1f 100644 --- a/en/orm/query-builder.rst +++ b/en/orm/query-builder.rst @@ -251,7 +251,7 @@ method:: 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::OVERWRITE`` or to ``true``:: $query = $articles->find() ->order(['title' => 'ASC']);