getMappingLocalColumn example



        if ($fk instanceof FkField && $fk->getReferenceDefinition() !== $association->getToManyReferenceDefinition()) {
            $violations[$definition->getClass()][] = sprintf(
                'Reference column %s of field %s should map to definition %s',
                $fk->getPropertyName(),
                $association->getPropertyName(),
                $association->getToManyReferenceDefinition()->getClass()
            );
        }

        $localColumn = $mapping->getFields()->getByStorageName($association->getMappingLocalColumn());
        if ($localColumn instanceof FkField && $localColumn->getReferenceDefinition() !== $definition) {
            $violations[$definition->getClass()][] = sprintf(
                'Local column %s of field %s should map to definition %s',
                $localColumn->getPropertyName(),
                $association->getPropertyName(),
                $definition->getClass()
            );
        }

        if ($definition->isVersionAware() && $reference->isVersionAware()) {
            $versionField = $mapping->getFields()->filter(fn (Field $field) => $field instanceof ReferenceVersionField && $field->getVersionReferenceDefinition() === $definition)->first();

            
if (!$association instanceof ManyToManyAssociationField) {
                throw new \RuntimeException(sprintf('Can not find association by property name %s', $field->getAssociationName()));
            }
            $parameters = ['ids' => $bytes];

            $replacement = [
                '#table#' => EntityDefinitionQueryHelper::escape($definition->getEntityName()),
                '#storage_name#' => EntityDefinitionQueryHelper::escape($field->getStorageName()),
                '#mapping_table#' => EntityDefinitionQueryHelper::escape($association->getMappingDefinition()->getEntityName()),
                '#reference_column#' => EntityDefinitionQueryHelper::escape($association->getMappingReferenceColumn()),
                '#mapping_column#' => EntityDefinitionQueryHelper::escape($association->getMappingLocalColumn()),
                '#join_column#' => EntityDefinitionQueryHelper::escape('id'),
            ];

            if ($definition->isInheritanceAware() && $association->is(Inherited::class)) {
                $replacement['#join_column#'] = EntityDefinitionQueryHelper::escape($association->getPropertyName());
            }
            $versionCondition = '';
            if ($definition->isVersionAware()) {
                $versionCondition = 'AND #table#.version_id = #mapping_table#.#unescaped_table#_version_id AND #table#.version_id = :version';

                $parameters['version'] = Uuid::fromHexToBytes($context->getVersionId());
                


            case $field instanceof ManyToManyAssociationField:
                $reference = $field->getToManyReferenceDefinition();
                $localField = $definition->getFields()->getByStorageName($field->getLocalField());
                $referenceField = $reference->getFields()->getByStorageName($field->getReferenceField());

                $mappingReference = $field->getMappingDefinition()->getFields()->getByStorageName(
                    $field->getMappingReferenceColumn()
                );
                $mappingLocal = $field->getMappingDefinition()->getFields()->getByStorageName(
                    $field->getMappingLocalColumn()
                );

                if (!$mappingReference) {
                    throw new \RuntimeException(sprintf('Can not find mapping entity field for storage field %s', $field->getMappingReferenceColumn()));
                }
                if (!$mappingLocal) {
                    throw new \RuntimeException(sprintf('Can not find mapping entity field for storage field %s', $field->getMappingLocalColumn()));
                }

                return [
                    'type' => 'association',
                    


        if (!$field instanceof ManyToManyAssociationField) {
            throw new \RuntimeException(sprintf('Unknown association class provided %s', $field::class));
        }

        $reference = $field->getReferenceDefinition();

        $mappingAlias = $definition->getEntityName() . '.' . $field->getPropertyName() . '.mapping';
        $alias = $definition->getEntityName() . '.' . $field->getPropertyName();

        $query->addSelect(self::accessor($mappingAlias$field->getMappingLocalColumn()) . ' as id');
        if ($definition->isVersionAware()) {
            $query->addSelect(self::accessor($mappingAlias$definition->getEntityName() . '_version_id'));
        }

        $query->from(self::escape($reference->getEntityName()), self::escape($mappingAlias));
        $query->addState($alias);

        $parameters = [
            '#mapping#' => self::escape($mappingAlias),
            '#source_column#' => self::escape($field->getMappingReferenceColumn()),
            '#alias#' => self::escape($alias),
            
$context->getQuery()->addState($alias);
        $context->getQuery()->addState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);

        $mappingAlias = $alias . '.mapping';

        $source = $this->getMappingSourceColumn($context->getAlias()$field$context->getContext());

        $parameters = [
            '#root#' => EntityDefinitionQueryHelper::escape($context->getAlias()),
            '#source#' => $source,
            '#alias#' => EntityDefinitionQueryHelper::escape($mappingAlias),
            '#reference_column#' => EntityDefinitionQueryHelper::escape($field->getMappingLocalColumn()),
        ];

        $context->getQuery()->leftJoin(
            EntityDefinitionQueryHelper::escape($context->getAlias()),
            EntityDefinitionQueryHelper::escape($field->getMappingDefinition()->getEntityName()),
            EntityDefinitionQueryHelper::escape($mappingAlias),
            str_replace(
                array_keys($parameters),
                array_values($parameters),
                '#source# = #alias#.#reference_column# '
                . $this->buildMappingVersionWhere($field$context->getDefinition())
            )
static::assertSame($field->getReferenceField()$actual->getReferenceField()$message);
                    static::assertSame($field->getLocalField()$actual->getLocalField()$message);
                    static::assertSame($field->getAutoload()$actual->getAutoload()$message);
                    static::assertSame($field->getReferenceEntity()$actual->getReferenceEntity()$message);
                }

                if ($field instanceof ManyToManyAssociationField) {
                    static::assertInstanceOf(ManyToManyAssociationField::class$actual$message);
                    static::assertSame($field->getReferenceField()$actual->getReferenceField()$message);
                    static::assertSame($field->getLocalField()$actual->getLocalField()$message);
                    static::assertSame($field->getAutoload()$actual->getAutoload()$message);
                    static::assertSame($field->getMappingLocalColumn()$actual->getMappingLocalColumn()$message);
                    static::assertSame($field->getMappingReferenceColumn()$actual->getMappingReferenceColumn()$message);
                    static::assertSame($field->getReferenceEntity()$actual->getReferenceEntity()$message);
                }

                if ($field instanceof ManyToOneAssociationField) {
                    static::assertInstanceOf(ManyToOneAssociationField::class$actual$message);
                    static::assertSame($field->getReferenceField()$actual->getReferenceField()$message);
                    static::assertSame($field->getStorageName()$actual->getStorageName()$message);
                    static::assertSame($field->getAutoload()$actual->getAutoload()$message);
                    static::assertSame($field->getReferenceEntity()$actual->getReferenceEntity()$message);
                }
            }
$propertyName = $associationField->getPropertyName();

        if ($associationField instanceof OneToOneAssociationField || $associationField instanceof ManyToOneAssociationField) {
            $template = 'IF(%s.%s IS NOT NULL, 1, 0) AS %s';
            $query->addSelect(sprintf($template, '`rule`', $this->escape($associationField->getStorageName())$propertyName));

            return;
        }

        if ($associationField instanceof ManyToManyAssociationField) {
            $mappingTable = $this->escape($associationField->getMappingDefinition()->getEntityName());
            $mappingLocalColumn = $this->escape($associationField->getMappingLocalColumn());
            $localColumn = $this->escape($associationField->getLocalField());

            $subQuery = (new QueryBuilder($this->connection))
                ->select('1')
                ->from($mappingTable)
                ->andWhere(sprintf('%s = `rule`.%s', $mappingLocalColumn$localColumn));

            $query->addSelect(sprintf($template$subQuery->getSQL()$propertyName));

            return;
        }

        


        $source = EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getLocalField());
        if ($field->is(Inherited::class) && $context->considerInheritance()) {
            $source = EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());
        }

        $parameters = [
            '#alias#' => EntityDefinitionQueryHelper::escape($root . '.' . $field->getPropertyName() . '.mapping'),
            '#mapping_reference_column#' => EntityDefinitionQueryHelper::escape($field->getMappingReferenceColumn()),
            '#mapping_table#' => EntityDefinitionQueryHelper::escape($mapping->getEntityName()),
            '#mapping_local_column#' => EntityDefinitionQueryHelper::escape($field->getMappingLocalColumn()),
            '#root#' => EntityDefinitionQueryHelper::escape($root),
            '#source#' => $source,
            '#property#' => EntityDefinitionQueryHelper::escape($root . '.' . $field->getPropertyName() . '.id_mapping'),
        ];

        $query->addSelect(
            str_replace(
                array_keys($parameters),
                array_values($parameters),
                '(SELECT GROUP_CONCAT(HEX(#alias#.#mapping_reference_column#) SEPARATOR \'||\') FROM #mapping_table# #alias# WHERE #alias#.#mapping_local_column# = #source#'
return (int) $total->executeQuery()->fetchOne();
    }

    private function addEmptyFilter(QueryBuilder $query): void
    {
        /** @var ManyToManyAssociationField[] $manyToManyFields */
        $manyToManyFields = $this->tagDefinition->getFields()->filter(fn (Field $field) => $field instanceof ManyToManyAssociationField);

        foreach ($manyToManyFields as $manyToManyField) {
            $mappingTable = EntityDefinitionQueryHelper::escape($manyToManyField->getMappingDefinition()->getEntityName());
            $mappingLocalColumn = EntityDefinitionQueryHelper::escape($manyToManyField->getMappingLocalColumn());

            $subQuery = (new QueryBuilder($this->connection))
                ->select([$mappingLocalColumn])
                ->from($mappingTable);

            $query->andWhere($query->expr()->notIn('`tag`.`id`', sprintf('(%s)', $subQuery->getSQL())));
        }
    }

    private function addDuplicateFilter(QueryBuilder $query): void
    {
        
// DELETE api/product/{id}/manufacturer/{id}         if ($association instanceof ManyToOneAssociationField || $association instanceof OneToOneAssociationField) {
            $this->executeWriteOperation($definition['id' => $id]$context, self::WRITE_DELETE);

            return $responseFactory->createRedirectResponse($definition$id$request$context);
        }

        // DELETE api/product/{id}/category/{id}         if ($association instanceof ManyToManyAssociationField) {
            /** @var Field $local */
            $local = $definition->getFields()->getByStorageName(
                $association->getMappingLocalColumn()
            );

            /** @var Field $reference */
            $reference = $definition->getFields()->getByStorageName(
                $association->getMappingReferenceColumn()
            );

            $mapping = [
                $local->getPropertyName() => $parent['value'],
                $reference->getPropertyName() => $id,
            ];
            
Home | Imprint | This part of the site doesn't use cookies.