protected function getDatabaseAssociationMappings(ClassMetadata $cm, $bTree = false)
{
$associations = $cm->getAssociationMappings();
$byReferenceMappings = $this->getByReferenceMappings($cm);
$associationMappings = [];
foreach ($associations as $association) {
$getterPlural = false;
$associationType = $association['type'];
switch ($association['type']) {
case ClassMetadataInfo::MANY_TO_MANY:
$associationType = 'MANY_TO_MANY';
$getterPlural = true;
break;
case ClassMetadataInfo::MANY_TO_ONE:
$associationType = 'MANY_TO_ONE';
$getterPlural = false;
break;
case ClassMetadataInfo::ONE_TO_MANY:
$associationType = 'ONE_TO_MANY';
$getterPlural = true;
break;
case ClassMetadataInfo::ONE_TO_ONE:
$associationType = 'ONE_TO_ONE';
$getterPlural = false;
break;
}
$getter = 'get' . ucfirst($association['fieldName']);
$getterField = lcfirst($cm->getReflectionClass()->getShortName()) . str_replace('.', '', $this->convertPHPToExtJSClassName($association['targetEntity']));
if ($getterPlural) {
$getterField .= 's';
}
$propertyAnnotations = $this->reader->getPropertyAnnotations($cm->getReflectionProperty($association['fieldName']));
$nullable = true;
foreach ($propertyAnnotations as $propertyAnnotation) {
$filter = "Symfony\\Component\\Validator\\Constraints\\NotNull";
if (substr(get_class($propertyAnnotation), 0, strlen($filter)) === $filter) {
$nullable = false;
}
}
// The self-referencing association may not be written for trees, because ExtJS can't load all nodes
// in one go.
if (!($bTree && $association['targetEntity'] == $cm->getName())) {
$byReference = false;
if (in_array($association['fieldName'], $byReferenceMappings)) {
$byReference = true;
}
$associationMappings[$associationType][] = ['name' => $association['fieldName'], 'nullable' => $nullable, 'target' => $this->convertPHPToExtJSClassName($association['targetEntity']), 'byReference' => $byReference, 'getter' => $getter, 'getterField' => $getterField];
}
}
return $associationMappings;
}