Commit 1c07ca16 authored by Alexandre Butynski's avatar Alexandre Butynski

Test and refactor EmbedsMany::createMany

parent 42a83a20
...@@ -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;
} }
......
...@@ -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'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment