/**
* Gets reference mapping for current field from current class or its descendants.
*
* @return array
* @throws MappingException
*/
private function getReferenceMapping()
{
$mapping = null;
try {
$mapping = $this->class->getFieldMapping($this->currentField);
} catch (MappingException $e) {
if (empty($this->class->discriminatorMap)) {
throw $e;
}
$foundIn = null;
foreach ($this->class->discriminatorMap as $child) {
$childClass = $this->dm->getClassMetadata($child);
if ($childClass->hasAssociation($this->currentField)) {
if ($mapping !== null && $mapping !== $childClass->getFieldMapping($this->currentField)) {
throw MappingException::referenceFieldConflict($this->currentField, $foundIn->name, $childClass->name);
}
$mapping = $childClass->getFieldMapping($this->currentField);
$foundIn = $childClass;
}
}
if ($mapping === null) {
throw MappingException::mappingNotFoundInClassNorDescendants($this->class->name, $this->currentField);
}
}
return $mapping;
}