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
c22670a5
Commit
c22670a5
authored
Aug 06, 2014
by
Kévin Bargoin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows an _id attribute of another type than string
parent
96036ab1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
Model.php
src/Jenssegers/Mongodb/Model.php
+5
-1
ModelTest.php
tests/ModelTest.php
+30
-1
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
c22670a5
...
@@ -54,8 +54,12 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -54,8 +54,12 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
// Return _id as string
// Return _id as string
if
(
array_key_exists
(
'_id'
,
$this
->
attributes
))
if
(
array_key_exists
(
'_id'
,
$this
->
attributes
))
{
{
if
(
$this
->
attributes
[
'_id'
]
instanceof
MongoId
)
{
return
(
string
)
$this
->
attributes
[
'_id'
];
return
(
string
)
$this
->
attributes
[
'_id'
];
}
}
return
$this
->
attributes
[
'_id'
];
}
}
}
/**
/**
...
...
tests/ModelTest.php
View file @
c22670a5
...
@@ -79,7 +79,7 @@ class ModelTest extends TestCase {
...
@@ -79,7 +79,7 @@ class ModelTest extends TestCase {
$this
->
assertEquals
(
20
,
$check
->
age
);
$this
->
assertEquals
(
20
,
$check
->
age
);
}
}
public
function
testManualId
()
public
function
testManual
String
Id
()
{
{
$user
=
new
User
;
$user
=
new
User
;
$user
->
_id
=
'4af9f23d8ead0e1d32000000'
;
$user
->
_id
=
'4af9f23d8ead0e1d32000000'
;
...
@@ -93,6 +93,35 @@ class ModelTest extends TestCase {
...
@@ -93,6 +93,35 @@ class ModelTest extends TestCase {
$raw
=
$user
->
getAttributes
();
$raw
=
$user
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoId'
,
$raw
[
'_id'
]);
$this
->
assertInstanceOf
(
'MongoId'
,
$raw
[
'_id'
]);
$user
=
new
User
;
$user
->
_id
=
'customId'
;
$user
->
name
=
'John Doe'
;
$user
->
title
=
'admin'
;
$user
->
age
=
35
;
$user
->
save
();
$this
->
assertEquals
(
true
,
$user
->
exists
);
$this
->
assertEquals
(
'customId'
,
$user
->
_id
);
$raw
=
$user
->
getAttributes
();
$this
->
assertInternalType
(
'string'
,
$raw
[
'_id'
]);
}
public
function
testManualIntId
()
{
$user
=
new
User
;
$user
->
_id
=
1
;
$user
->
name
=
'John Doe'
;
$user
->
title
=
'admin'
;
$user
->
age
=
35
;
$user
->
save
();
$this
->
assertEquals
(
true
,
$user
->
exists
);
$this
->
assertEquals
(
1
,
$user
->
_id
);
$raw
=
$user
->
getAttributes
();
$this
->
assertInternalType
(
'integer'
,
$raw
[
'_id'
]);
}
}
public
function
testDelete
()
public
function
testDelete
()
...
...
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