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
120f936b
Commit
120f936b
authored
Mar 04, 2014
by
Alexandre Butynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MongoId creation of embedded models work even if the base _id is an empty string
+ Laravel coding style of '!'
parent
8ea8b96f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+2
-2
RelationsTest.php
tests/RelationsTest.php
+8
-2
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
120f936b
...
...
@@ -141,7 +141,7 @@ class EmbedsMany extends Relation {
public
function
save
(
Model
$model
)
{
// Insert a new document.
if
(
!
$model
->
exists
)
if
(
!
$model
->
exists
)
{
return
$this
->
performInsert
(
$model
);
}
...
...
@@ -162,7 +162,7 @@ class EmbedsMany extends Relation {
protected
function
performInsert
(
Model
$model
)
{
// Create a new key.
if
(
!
isset
(
$model
[
'_id'
]))
if
(
!
isset
(
$model
[
'_id'
])
or
empty
(
$model
[
'_id'
]))
{
$model
->
setAttribute
(
'_id'
,
new
MongoId
);
}
...
...
tests/RelationsTest.php
View file @
120f936b
...
...
@@ -341,12 +341,18 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
public
function
testEmbedsManyCreate
()
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
->
addresses
()
->
create
(
array
(
'city'
=>
'Bruxelles'
));
$user
=
User
::
create
(
array
());
$address
=
$user
->
addresses
()
->
create
(
array
(
'city'
=>
'Bruxelles'
));
$this
->
assertInstanceOf
(
'Address'
,
$address
);
$this
->
assertInstanceOf
(
'MongoID'
,
$address
->
_id
);
$this
->
assertEquals
(
array
(
'Bruxelles'
),
$user
->
addresses
->
lists
(
'city'
));
$freshUser
=
User
::
find
(
$user
->
id
);
$this
->
assertEquals
(
array
(
'Bruxelles'
),
$freshUser
->
addresses
->
lists
(
'city'
));
$user
=
User
::
create
(
array
());
$address
=
$user
->
addresses
()
->
create
(
array
(
'_id'
=>
''
,
'city'
=>
'Bruxelles'
));
$this
->
assertInstanceOf
(
'MongoID'
,
$address
->
_id
);
}
public
function
testEmbedsManyDestroy
()
...
...
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