Skip to content

Commit f9287f5

Browse files
committed
Merge pull request #170 from neoxia/master-bug-fix
Fix toArray() infinite loop bug in embeds many relation
2 parents 84f1df5 + ae62146 commit f9287f5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ protected function toCollection(array $results = array())
487487

488488
// Attatch the parent relation to the embedded model.
489489
$model->setRelation($this->foreignKey, $this->parent);
490+
$model->setHidden(array_merge($model->getHidden(), array($this->foreignKey)));
490491

491492
$models[] = $model;
492493
}

tests/RelationsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ public function testEmbedsManySave()
342342
$this->assertInstanceOf('DateTime', $address->created_at);
343343
$this->assertInstanceOf('DateTime', $address->updated_at);
344344
$this->assertInstanceOf('User', $address->user);
345+
$this->assertEmpty($address->relationsToArray()); // prevent infinite loop
345346

346347
$user = User::find($user->_id);
347348
$user->addresses()->save(new Address(array('city' => 'Bruxelles')));

0 commit comments

Comments
 (0)