File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
src/Jenssegers/Mongodb/Query Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change @@ -148,8 +148,14 @@ public function testOrder()
148148 $ user = User::whereNotNull ('age ' )->orderBy ('age ' , 'desc ' )->first ();
149149 $ this ->assertEquals (37 , $ user ->age );
150150
151- $ user = User::whereNotNull ('age ' )->orderBy ('natural ' )->first ();
151+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' , ' asc ' )->first ();
152152 $ this ->assertEquals (35 , $ user ->age );
153+
154+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' , 'ASC ' )->first ();
155+ $ this ->assertEquals (35 , $ user ->age );
156+
157+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' , 'desc ' )->first ();
158+ $ this ->assertEquals (35 , $ user ->age );
153159 }
154160
155161 public function testGroupBy ()
You can’t perform that action at this time.
0 commit comments