Skip to content

Commit

Permalink
Merge pull request #1983 from malarzm/gh-1961
Browse files Browse the repository at this point in the history
Allow returning null from getAssociationTargetClass
  • Loading branch information
alcaeus authored Mar 29, 2019
2 parents 7f0e11e + d251ea5 commit c1b0137
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ public function getTypeOfField($fieldName) : ?string
/**
* {@inheritDoc}
*/
public function getAssociationTargetClass($assocName) : string
public function getAssociationTargetClass($assocName) : ?string
{
if (! isset($this->associationMappings[$assocName])) {
throw new InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
Expand Down
13 changes: 13 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ public function testMapManyToManyJoinTableDefaults()
$this->assertInternalType('array', $assoc);
}

public function testGetAssociationTargetClassWithoutTargetDocument()
{
$cm = new ClassMetadata(CmsUser::class);
$cm->mapManyEmbedded(
[
'fieldName' => 'groups',
'targetDocument' => null,
]
);

$this->assertNull($cm->getAssociationTargetClass('groups'));
}

/**
* @group DDC-115
*/
Expand Down

0 comments on commit c1b0137

Please sign in to comment.