/** * Gets the type of an association between the given entities * * @param string $entityClass * @param string $associationName * @param string $targetEntityClass * * @return int */ protected function getAssociationType($entityClass, $associationName, $targetEntityClass) { $associations = $this->context->getClassMetadata($entityClass)->getAssociationsByTargetClass($targetEntityClass); if (!array_key_exists($associationName, $associations)) { return 0; } return $associations[$associationName]['type']; }
/** * Get SELECT fields for optimized Query Builder. * * By default all identifier fields are added. * If some of them are selected as DISTINCT in original Query Builder, * then them also should be selected as DISTINCT in optimized Query Builder. * * @param array $originalQueryParts * @return array */ protected function getFieldsToSelect(array $originalQueryParts) { $fieldsToSelect = []; foreach ($originalQueryParts['from'] as $from) { /** @var Expr\From $from */ $fieldNames = $this->context->getClassMetadata($from->getFrom())->getIdentifierFieldNames(); foreach ($fieldNames as $fieldName) { $selectField = $from->getAlias() . '.' . $fieldName; /** @var Expr\Select $originalSelect */ foreach ($originalQueryParts['select'] as $originalSelect) { foreach ($originalSelect->getParts() as $part) { if (strtolower((string) $part) === 'distinct ' . $selectField) { $selectField = 'DISTINCT ' . $selectField; break; } } } $fieldsToSelect[] = $selectField; } } return $fieldsToSelect; }