File tree 2 files changed +13
-7
lines changed
src/Jenssegers/Mongodb/Query
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)
281
281
* @param string $direction
282
282
* @return Builder
283
283
*/
284
- public function orderBy ($ column , $ direction = null )
284
+ public function orderBy ($ column , $ direction = ' asc ' )
285
285
{
286
- if (is_null ($ direction ) && $ column == 'natural ' )
286
+ $ direction = (strtolower ($ direction ) == 'asc ' ? 1 : -1 );
287
+
288
+ if ($ column == 'natural ' )
287
289
{
288
- $ this ->orders ['$natural ' ] = 1 ;
290
+ $ this ->orders ['$natural ' ] = $ direction ;
289
291
}
290
292
else
291
293
{
292
- $ direction = $ direction ?: 'asc ' ;
293
-
294
- $ this ->orders [$ column ] = (strtolower ($ direction ) == 'asc ' ? 1 : -1 );
294
+ $ this ->orders [$ column ] = $ direction ;
295
295
}
296
296
297
297
return $ this ;
Original file line number Diff line number Diff line change @@ -148,8 +148,14 @@ public function testOrder()
148
148
$ user = User::whereNotNull ('age ' )->orderBy ('age ' , 'desc ' )->first ();
149
149
$ this ->assertEquals (37 , $ user ->age );
150
150
151
- $ user = User::whereNotNull ('age ' )->orderBy ('natural ' )->first ();
151
+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' , ' asc ' )->first ();
152
152
$ 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 );
153
159
}
154
160
155
161
public function testGroupBy ()
You can’t perform that action at this time.
0 commit comments