Skip to content

Commit d6e625e

Browse files
committed
Add PR mongodb#741
1 parent 7438f7b commit d6e625e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ protected function getEmbedded()
217217
$attributes = $this->parent->getAttributes();
218218

219219
// Get embedded models form parent attributes.
220-
$embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : [];
220+
$embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : null;
221221

222222
return $embedded;
223223
}

tests/EmbeddedRelationsTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,12 @@ public function testEmbedsOneAssociate()
506506
$this->assertEquals('Mark Doe', $user->father->name);
507507
}
508508

509+
public function testEmbedsOneNullAssociation()
510+
{
511+
$user = User::create();
512+
$this->assertNull($user->father);
513+
}
514+
509515
public function testEmbedsOneDelete()
510516
{
511517
$user = User::create(['name' => 'John Doe']);

0 commit comments

Comments
 (0)