Skip to content

Commit d15e1e1

Browse files
committed
Add natural reverse (descending) sort option
1 parent 93b7afd commit d15e1e1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,17 @@ public function distinct($column = false)
281281
* @param string $direction
282282
* @return Builder
283283
*/
284-
public function orderBy($column, $direction = null)
284+
public function orderBy($column, $direction = 'asc')
285285
{
286-
if (is_null($direction) && $column == 'natural')
286+
$direction = (strtolower($direction) == 'asc' ? 1 : -1);
287+
288+
if ($column == 'natural')
287289
{
288-
$this->orders['$natural'] = 1;
290+
$this->orders['$natural'] = $direction;
289291
}
290292
else
291293
{
292-
$direction = $direction ?: 'asc';
293-
294-
$this->orders[$column] = (strtolower($direction) == 'asc' ? 1 : -1);
294+
$this->orders[$column] = $direction;
295295
}
296296

297297
return $this;

0 commit comments

Comments
 (0)