Commit f9287f52 authored by Jens Segers's avatar Jens Segers

Merge pull request #170 from neoxia/master-bug-fix

Fix toArray() infinite loop bug in embeds many relation
parents 84f1df5e ae621465
...@@ -487,6 +487,7 @@ class EmbedsMany extends Relation { ...@@ -487,6 +487,7 @@ class EmbedsMany extends Relation {
// Attatch the parent relation to the embedded model. // Attatch the parent relation to the embedded model.
$model->setRelation($this->foreignKey, $this->parent); $model->setRelation($this->foreignKey, $this->parent);
$model->setHidden(array_merge($model->getHidden(), array($this->foreignKey)));
$models[] = $model; $models[] = $model;
} }
......
...@@ -342,6 +342,7 @@ class RelationsTest extends PHPUnit_Framework_TestCase { ...@@ -342,6 +342,7 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$this->assertInstanceOf('DateTime', $address->created_at); $this->assertInstanceOf('DateTime', $address->created_at);
$this->assertInstanceOf('DateTime', $address->updated_at); $this->assertInstanceOf('DateTime', $address->updated_at);
$this->assertInstanceOf('User', $address->user); $this->assertInstanceOf('User', $address->user);
$this->assertEmpty($address->relationsToArray()); // prevent infinite loop
$user = User::find($user->_id); $user = User::find($user->_id);
$user->addresses()->save(new Address(array('city' => 'Bruxelles'))); $user->addresses()->save(new Address(array('city' => 'Bruxelles')));
......
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