File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
src/Jenssegers/Mongodb/Relations Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -265,12 +265,7 @@ public function create(array $attributes)
265265 */
266266 public function createMany (array $ records )
267267 {
268- $ instances = array ();
269-
270- foreach ($ records as $ record )
271- {
272- $ instances [] = $ this ->create ($ record );
273- }
268+ $ instances = array_map (array ($ this , 'create ' ), $ records );
274269
275270 return $ instances ;
276271 }
Original file line number Diff line number Diff line change @@ -355,6 +355,18 @@ public function testEmbedsManyCreate()
355355 $ this ->assertInstanceOf ('MongoID ' , $ address ->_id );
356356 }
357357
358+ public function testEmbedsManyCreateMany ()
359+ {
360+ $ user = User::create (array ());
361+ list ($ bruxelles , $ paris ) = $ user ->addresses ()->createMany (array (array ('city ' => 'Bruxelles ' ), array ('city ' => 'Paris ' )));
362+ $ this ->assertInstanceOf ('Address ' , $ bruxelles );
363+ $ this ->assertEquals ('Bruxelles ' , $ bruxelles ->city );
364+ $ this ->assertEquals (array ('Bruxelles ' , 'Paris ' ), $ user ->addresses ->lists ('city ' ));
365+
366+ $ freshUser = User::find ($ user ->id );
367+ $ this ->assertEquals (array ('Bruxelles ' , 'Paris ' ), $ freshUser ->addresses ->lists ('city ' ));
368+ }
369+
358370 public function testEmbedsManyDestroy ()
359371 {
360372 $ user = User::create (array ('name ' => 'John Doe ' ));
You can’t perform that action at this time.
0 commit comments