Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
cbb5273d
Commit
cbb5273d
authored
Mar 04, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #149 from khamkham/master
Add natural reverse (descending) sort option
parents
93b7afd5
9a5b24f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+6
-6
QueryTest.php
tests/QueryTest.php
+7
-1
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
cbb5273d
...
...
@@ -281,17 +281,17 @@ class Builder extends \Illuminate\Database\Query\Builder {
* @param string $direction
* @return Builder
*/
public
function
orderBy
(
$column
,
$direction
=
null
)
public
function
orderBy
(
$column
,
$direction
=
'asc'
)
{
if
(
is_null
(
$direction
)
&&
$column
==
'natural'
)
$direction
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
if
(
$column
==
'natural'
)
{
$this
->
orders
[
'$natural'
]
=
1
;
$this
->
orders
[
'$natural'
]
=
$direction
;
}
else
{
$direction
=
$direction
?:
'asc'
;
$this
->
orders
[
$column
]
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
$this
->
orders
[
$column
]
=
$direction
;
}
return
$this
;
...
...
tests/QueryTest.php
View file @
cbb5273d
...
...
@@ -148,8 +148,14 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'desc'
)
->
first
();
$this
->
assertEquals
(
37
,
$user
->
age
);
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'natural'
)
->
first
();
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'natural'
,
'asc'
)
->
first
();
$this
->
assertEquals
(
35
,
$user
->
age
);
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'natural'
,
'ASC'
)
->
first
();
$this
->
assertEquals
(
35
,
$user
->
age
);
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'natural'
,
'desc'
)
->
first
();
$this
->
assertEquals
(
35
,
$user
->
age
);
}
public
function
testGroupBy
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment