diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php index 02a43ce3a..3d0b59e61 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php @@ -233,7 +233,7 @@ protected function getEmbedded() // Get raw attributes to skip relations and accessors. $attributes = $this->parent->getAttributes(); - $embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : []; + $embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : null; return $embedded; } diff --git a/tests/EmbeddedRelationsTest.php b/tests/EmbeddedRelationsTest.php index a212dddc7..c5e394cf8 100644 --- a/tests/EmbeddedRelationsTest.php +++ b/tests/EmbeddedRelationsTest.php @@ -505,6 +505,12 @@ public function testEmbedsOneAssociate() $this->assertEquals('Mark Doe', $user->father->name); } + public function testEmbedsOneNullAssociation() + { + $user = User::create(); + $this->assertNull($user->father); + } + public function testEmbedsOneDelete() { $user = User::create(['name' => 'John Doe']);