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
932bb693
Commit
932bb693
authored
Apr 15, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ID conversion for toJson and toArray
parent
3f30502c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
Model.php
src/Jenssegers/Mongodb/Model.php
+10
-6
ModelTest.php
tests/ModelTest.php
+1
-0
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
932bb693
...
@@ -195,14 +195,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -195,14 +195,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
{
{
$attributes
=
parent
::
attributesToArray
();
$attributes
=
parent
::
attributesToArray
();
// Because the original Eloquent never returns objects, we convert
// MongoDB related objects to a string representation. This kind
// of mimics the SQL behaviour so that dates are formatted
// nicely when your models are converted to JSON.
foreach
(
$attributes
as
&
$value
)
foreach
(
$attributes
as
&
$value
)
{
{
/**
if
(
$value
instanceof
MongoId
)
* Here we convert MongoDate instances to string. This mimics
{
* original SQL behaviour so that dates are formatted nicely
$value
=
(
string
)
$value
;
* when your models are converted to JSON.
}
*/
if
(
$value
instanceof
MongoDate
)
else
if
(
$value
instanceof
MongoDate
)
{
{
$value
=
$this
->
asDateTime
(
$value
)
->
format
(
$this
->
getDateFormat
());
$value
=
$this
->
asDateTime
(
$value
)
->
format
(
$this
->
getDateFormat
());
}
}
...
...
tests/ModelTest.php
View file @
932bb693
...
@@ -287,6 +287,7 @@ class ModelTest extends TestCase {
...
@@ -287,6 +287,7 @@ class ModelTest extends TestCase {
$this
->
assertEquals
(
array
(
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
),
$keys
);
$this
->
assertEquals
(
array
(
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
),
$keys
);
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'_id'
]));
}
}
public
function
testUnset
()
public
function
testUnset
()
...
...
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