Commit 3c20c17a authored by Jens Segers's avatar Jens Segers

Merge pull request #741 from Rezouce/2.3

EmbedsOne relationship returns null when no model is associated
parents 6e9b5f4f 3bc51204
...@@ -233,7 +233,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -233,7 +233,7 @@ abstract class EmbedsOneOrMany extends Relation
// Get raw attributes to skip relations and accessors. // Get raw attributes to skip relations and accessors.
$attributes = $this->parent->getAttributes(); $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; return $embedded;
} }
......
...@@ -505,6 +505,12 @@ class EmbeddedRelationsTest extends TestCase ...@@ -505,6 +505,12 @@ class EmbeddedRelationsTest extends TestCase
$this->assertEquals('Mark Doe', $user->father->name); $this->assertEquals('Mark Doe', $user->father->name);
} }
public function testEmbedsOneNullAssociation()
{
$user = User::create();
$this->assertNull($user->father);
}
public function testEmbedsOneDelete() public function testEmbedsOneDelete()
{ {
$user = User::create(['name' => 'John Doe']); $user = User::create(['name' => 'John Doe']);
......
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