Skip to content

Commit

Permalink
[relationships] fixed working with empty hasOne relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Sep 15, 2014
1 parent 6e3f54e commit 824fd7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Relationships/HasOne.php
Expand Up @@ -116,7 +116,7 @@ public function set($value, $forceNULL = FALSE)
public function getEntity($collectionName = NULL)
{
if ($this->value === FALSE) {
if (!$this->parent->isPersisted()) {
if (!$this->parent->isPersisted() || $this->primaryValue === NULL) {
return NULL;
}

Expand Down
Expand Up @@ -46,6 +46,17 @@ class RelationshipManyHasOneTest extends DatabaseTestCase
Assert::same([1, 1, 2, 2], $authors);
}


public function testEmpty()
{
/** @var Book $book */
$book = $this->orm->books->getById(2);
Assert::null($book->translator);

$book = new Book();
Assert::null($book->translator);
}

}


Expand Down

0 comments on commit 824fd7a

Please sign in to comment.