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
1c07ca16
Commit
1c07ca16
authored
Mar 04, 2014
by
Alexandre Butynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and refactor EmbedsMany::createMany
parent
42a83a20
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+1
-6
RelationsTest.php
tests/RelationsTest.php
+12
-0
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
1c07ca16
...
@@ -265,12 +265,7 @@ class EmbedsMany extends Relation {
...
@@ -265,12 +265,7 @@ class EmbedsMany extends Relation {
*/
*/
public
function
createMany
(
array
$records
)
public
function
createMany
(
array
$records
)
{
{
$instances
=
array
();
$instances
=
array_map
(
array
(
$this
,
'create'
),
$records
);
foreach
(
$records
as
$record
)
{
$instances
[]
=
$this
->
create
(
$record
);
}
return
$instances
;
return
$instances
;
}
}
...
...
tests/RelationsTest.php
View file @
1c07ca16
...
@@ -355,6 +355,18 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
...
@@ -355,6 +355,18 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$this
->
assertInstanceOf
(
'MongoID'
,
$address
->
_id
);
$this
->
assertInstanceOf
(
'MongoID'
,
$address
->
_id
);
}
}
public
function
testEmbedsManyCreateMany
()
{
$user
=
User
::
create
(
array
());
list
(
$bruxelles
,
$paris
)
=
$user
->
addresses
()
->
createMany
(
array
(
array
(
'city'
=>
'Bruxelles'
),
array
(
'city'
=>
'Paris'
)));
$this
->
assertInstanceOf
(
'Address'
,
$bruxelles
);
$this
->
assertEquals
(
'Bruxelles'
,
$bruxelles
->
city
);
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$user
->
addresses
->
lists
(
'city'
));
$freshUser
=
User
::
find
(
$user
->
id
);
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$freshUser
->
addresses
->
lists
(
'city'
));
}
public
function
testEmbedsManyDestroy
()
public
function
testEmbedsManyDestroy
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
...
...
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