Skip to content

Commit

Permalink
Merge pull request #2064 from alcaeus/incomplete-discriminator-map-de…
Browse files Browse the repository at this point in the history
…precation

Add missing deprecation notice for incomplete embedded associations
  • Loading branch information
alcaeus authored Sep 24, 2019
2 parents 3eaf689 + bb40c36 commit acfc6db
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,15 @@ public function prepareEmbeddedDocumentValue(array $embeddedMapping, $embeddedDo
*/
if ( ! isset($embeddedMapping['targetDocument'])) {
$discriminatorField = $embeddedMapping['discriminatorField'];
$discriminatorValue = isset($embeddedMapping['discriminatorMap'])
? array_search($class->name, $embeddedMapping['discriminatorMap'])
: $class->name;

/* If the discriminator value was not found in the map, use the full
* class name. In the future, it may be preferable to throw an
* exception here (perhaps based on some strictness option).
*
* @see DocumentManager::createDBRef()
*/
if ($discriminatorValue === false) {
if (! empty($embeddedMapping['discriminatorMap'])) {
$discriminatorValue = array_search($class->name, $embeddedMapping['discriminatorMap']);

if ($discriminatorValue === false) {
@trigger_error(sprintf('Document class "%s" is unlisted in the discriminator map for embedded field "%s". This is deprecated and will throw an exception in doctrine/mongodb-odm 2.0.', $class->name, $mapping['name']), E_USER_DEPRECATED);

$discriminatorValue = $class->name;
}
} else {
$discriminatorValue = $class->name;
}

Expand Down

0 comments on commit acfc6db

Please sign in to comment.