Skip to content

Commit

Permalink
Merge pull request #741 from Rezouce/2.3
Browse files Browse the repository at this point in the history
EmbedsOne relationship returns null when no model is associated
  • Loading branch information
jenssegers committed Feb 15, 2016
2 parents 6e9b5f4 + 3bc5120 commit 3c20c17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/EmbeddedRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 3c20c17

Please sign in to comment.