getAssociationMapping example

public function guessType(string $class, string $property): ?TypeGuess
    {
        if (!$ret = $this->getMetadata($class)) {
            return new TypeGuess(TextType::class[], Guess::LOW_CONFIDENCE);
        }

        [$metadata$name] = $ret;

        if ($metadata->hasAssociation($property)) {
            $multiple = $metadata->isCollectionValuedAssociation($property);
            $mapping = $metadata->getAssociationMapping($property);

            return new TypeGuess(EntityType::class['em' => $name, 'class' => $mapping['targetEntity'], 'multiple' => $multiple], Guess::HIGH_CONFIDENCE);
        }

        return match ($metadata->getTypeOfField($property)) {
            Types::ARRAY,
            Types::SIMPLE_ARRAY => new TypeGuess(CollectionType::class[], Guess::MEDIUM_CONFIDENCE),
            Types::BOOLEAN => new TypeGuess(CheckboxType::class[], Guess::HIGH_CONFIDENCE),
            Types::DATETIME_MUTABLE,
            Types::DATETIMETZ_MUTABLE,
            'vardatetime' => new TypeGuess(DateTimeType::class[], Guess::HIGH_CONFIDENCE),
            
public function getTypes(string $class, string $property, array $context = []): ?array
    {
        if (null === $metadata = $this->getMetadata($class)) {
            return null;
        }

        if ($metadata->hasAssociation($property)) {
            $class = $metadata->getAssociationTargetClass($property);

            if ($metadata->isSingleValuedAssociation($property)) {
                if ($metadata instanceof ClassMetadataInfo) {
                    $associationMapping = $metadata->getAssociationMapping($property);

                    $nullable = $this->isAssociationNullable($associationMapping);
                } else {
                    $nullable = false;
                }

                return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable$class)];
            }

            $collectionKeyType = Type::BUILTIN_TYPE_INT;

            
$targetEntity = $this->load($identifier, null, $assoc$hints);

            // Complete bidirectional association, if necessary             if ($targetEntity !== null && $isInverseSingleValued) {
                $targetClass->reflFields[$assoc['inversedBy']]->setValue($targetEntity$sourceEntity);
            }

            return $targetEntity;
        }

        $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
        $owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']);

        $computedIdentifier = [];

        // TRICKY: since the association is specular source and target are flipped         foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) {
            if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
                throw MappingException::joinColumnMustPointToMappedField(
                    $sourceClass->name,
                    $sourceKeyColumn
                );
            }

            

    protected function getOwningSideAssociation($model$property)
    {
        $metaData = $this->getManager()->getClassMetadata($model);
        /** @var array{targetEntity: class-string<ModelEntity>, mappedBy: string, isOwningSide: bool} $mapping */
        $mapping = $metaData->getAssociationMapping($property);

        if ($mapping['isOwningSide']) {
            return $mapping;
        }

        $associationMetaData = $this->getManager()->getClassMetadata($mapping['targetEntity']);

        return $associationMetaData->getAssociationMapping($mapping['mappedBy']);
    }

    /** * Helper function which adds the listing sort conditions to the passed query builder object. * * @example * The backend listing store of shopware creates a following sort array: * $sort = array( * array('property' => 'name', 'direction' => 'DESC'), * array('property' => 'id', 'direction' => 'ASC') * ); * * Important: Doctrine requires the query builder field alias for each field. * You can get a field mapping over the {@link #getModelFields} function. * This function creates an associated array with the model field name as array key * and as value an array with the query builder field alias under $field['alias']. * * Shopware resolves the passed Ext JS name over this function and use the alias of the field * to sort the query builder. * * @param array<array{property: string, direction: string}> $sort * @param class-string<ModelEntity> $model * @param string $alias * @param array<string> $whiteList * * @return array<array{property: string, direction: string}> */
Home | Imprint | This part of the site doesn't use cookies.