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
93b7afd5
Commit
93b7afd5
authored
Mar 04, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added natural sorting, fixes #148
parent
c1af77aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+11
-2
QueryTest.php
tests/QueryTest.php
+3
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
93b7afd5
...
@@ -281,9 +281,18 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -281,9 +281,18 @@ class Builder extends \Illuminate\Database\Query\Builder {
* @param string $direction
* @param string $direction
* @return Builder
* @return Builder
*/
*/
public
function
orderBy
(
$column
,
$direction
=
'asc'
)
public
function
orderBy
(
$column
,
$direction
=
null
)
{
{
$this
->
orders
[
$column
]
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
if
(
is_null
(
$direction
)
&&
$column
==
'natural'
)
{
$this
->
orders
[
'$natural'
]
=
1
;
}
else
{
$direction
=
$direction
?:
'asc'
;
$this
->
orders
[
$column
]
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
}
return
$this
;
return
$this
;
}
}
...
...
tests/QueryTest.php
View file @
93b7afd5
...
@@ -147,6 +147,9 @@ class QueryTest extends PHPUnit_Framework_TestCase {
...
@@ -147,6 +147,9 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'desc'
)
->
first
();
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'desc'
)
->
first
();
$this
->
assertEquals
(
37
,
$user
->
age
);
$this
->
assertEquals
(
37
,
$user
->
age
);
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'natural'
)
->
first
();
$this
->
assertEquals
(
35
,
$user
->
age
);
}
}
public
function
testGroupBy
()
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