Permalink
Browse files

added onMissing configuration to references one to allow return null

  • Loading branch information...
1 parent b9e06c1 commit 957d6c6f54c8ed0762ab63b16a057d1e631bc002 @pablodip pablodip committed Mar 6, 2012
@@ -42,7 +42,11 @@
return null;
}
if (!$document = $this->getMandango()->getRepository('{{ referenceOne.class }}')->findOneById($id)) {
+{% if referenceOne.onMissing is defined and referenceOne.onMissing == 'returnNull' %}
+ $document = null;
+{% else %}
throw new \RuntimeException('The reference "{{ name }}" does not exist.');
+{% endif %}
}
$this->data['referencesOne']['{{ name }}'] = $document;
}
@@ -153,6 +153,13 @@ public function testReferencesOneGetterQueryNotExist()
$article->getAuthor();
}
+ public function testReferencesOneGetterOnMissingReturnNull()
+ {
+ $article = $this->mandango->create('Model\Article');
+ $article->setInformationId(new \MongoId('123'));
+ $this->assertNull($article->getInformation());
+ }
+
public function testReferencesManyGetter()
{
$article = $this->mandango->create('Model\Article');
View
@@ -23,7 +23,7 @@
),
'referencesOne' => array(
'author' => array('class' => 'Model\Author', 'field' => 'authorId'),
- 'information' => array('class' => 'Model\ArticleInformation', 'field' => 'informationId'),
+ 'information' => array('class' => 'Model\ArticleInformation', 'field' => 'informationId', 'onMissing' => 'returnNull'),
'like' => array('polymorphic' => true, 'field' => 'likeRef'),
'friend' => array('polymorphic' => true, 'field' => 'friendRef', 'discriminatorField' => 'name', 'discriminatorMap' => array(
'au' => 'Model\Author',

0 comments on commit 957d6c6

Please sign in to comment.