getLocalField example

$context->getQuery()->addState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);

        $alias = $context->getAlias() . '.' . $field->getPropertyName();
        if ($context->getQuery()->hasState($alias)) {
            return $alias;
        }

        $context->getQuery()->addState($alias);

        $routeParamKey = 'route_' . Uuid::randomHex();
        $parameters = [
            '#source#' => EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getLocalField()),
            '#alias#' => EntityDefinitionQueryHelper::escape($alias),
            '#reference_column#' => EntityDefinitionQueryHelper::escape($field->getReferenceField()),
            '#root#' => EntityDefinitionQueryHelper::escape($context->getAlias()),
        ];

        $context->getQuery()->leftJoin(
            EntityDefinitionQueryHelper::escape($context->getAlias()),
            EntityDefinitionQueryHelper::escape($field->getReferenceDefinition()->getEntityName()),
            EntityDefinitionQueryHelper::escape($alias),
            str_replace(
                array_keys($parameters),
                
$reference = $association->getReferenceDefinition();

        $associationViolations = [];

        $reverseSide = $reference->getFields()->filter(
            function DField $field) use ($association$definition) {
                if (!$field instanceof OneToManyAssociationField) {
                    return false;
                }
                $reference = $field->getReferenceDefinition();

                return $field->getLocalField() === $association->getReferenceField() && $reference === $definition;
            }
        )->first();

        if ($reverseSide === null) {
            $associationViolations[$definition->getClass()][] = sprintf(
                'Missing reverse one-to-many association for %s <-> %s (%s)',
                $definition->getClass(),
                $association->getReferenceDefinition()->getClass(),
                $association->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;
        }

        

        if (!$field instanceof OneToManyAssociationField) {
            throw DataAbstractionLayerException::invalidSerializerField(OneToManyAssociationField::class$field);
        }

        $key = $field->getPropertyName();
        $value = $data[$key] ?? null;
        if ($value === null) {
            return $data;
        }

        $id = $parameters->getContext()->get($parameters->getDefinition()->getEntityName()$field->getLocalField());
        $reference = $field->getReferenceDefinition();

        $fkField = $reference->getFields()->getByStorageName($field->getReferenceField());

        if (!$fkField) {
            throw new \RuntimeException(sprintf('Can not find fk field for accessor %s.%s', $reference->getEntityName()$field->getReferenceField()));
        }

        // allows to reset the association for a none cascade delete         $fk = $fkField->getPropertyName();

        
private function getSourceColumn(AssociationField $association, Context $context): string
    {
        if ($association->is(Inherited::class) && $context->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($association->getPropertyName());
        }

        if ($association instanceof ManyToOneAssociationField || $association instanceof OneToOneAssociationField) {
            return EntityDefinitionQueryHelper::escape($association->getStorageName());
        }

        if ($association instanceof OneToManyAssociationField) {
            return EntityDefinitionQueryHelper::escape($association->getLocalField());
        }

        if ($association instanceof ManyToManyAssociationField) {
            return EntityDefinitionQueryHelper::escape($association->getLocalField());
        }

        throw new \RuntimeException(sprintf('Unknown association class provided %s', $association::class));
    }
}
$versionField = $definition->getEntityName() . '_version_id';

        return ' AND #root#.`version_id` = #alias#.`' . $versionField . '`';
    }

    private function getMappingSourceColumn(string $root, ManyToManyAssociationField $association, Context $context): string
    {
        if ($association->is(Inherited::class) && $context->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($association->getPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($association->getLocalField());
    }

    private function getReferenceColumn(FieldResolverContext $context, ManyToManyAssociationField $field): string
    {
        if (!$field->is(ReverseInherited::class)) {
            return EntityDefinitionQueryHelper::escape($field->getReferenceField());
        }

        if (!$context->getContext()->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($field->getReferenceField());
        }

        
static::assertTrue($field->is($flag::class)$message . ' - flag not expected: ' . $flag::class);
                }

                if ($field instanceof StorageAware) {
                    static::assertInstanceOf(StorageAware::class$actual$message);
                    static::assertSame($field->getStorageName()$actual->getStorageName()$message);
                }

                if ($field instanceof OneToManyAssociationField) {
                    static::assertInstanceOf(OneToManyAssociationField::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->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);
                    
return $this->createJsonObjectType($definition$field$flags);

                // association fields             case $field instanceof OneToManyAssociationField:
            case $field instanceof ChildrenAssociationField:
            case $field instanceof TranslationsAssociationField:
                if (!$field instanceof OneToManyAssociationField) {
                    throw new \RuntimeException('Field should extend OneToManyAssociationField');
                }

                $reference = $field->getReferenceDefinition();
                $localField = $definition->getFields()->getByStorageName($field->getLocalField());
                $referenceField = $reference->getFields()->getByStorageName($field->getReferenceField());

                $primary = $reference->getPrimaryKeys()->first();
                if (!$primary) {
                    throw new \RuntimeException(sprintf('No primary key defined for %s', $reference->getEntityName()));
                }

                return [
                    'type' => 'association',
                    'relation' => 'one_to_many',
                    'entity' => $reference->getEntityName(),
                    


        return ' AND #root#.version_id = #alias#.version_id';
    }

    private function getSourceColumn(FieldResolverContext $context, OneToManyAssociationField $field): string
    {
        if ($field->is(Inherited::class) && $context->getContext()->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getLocalField());
    }

    private function getReferenceColumn(FieldResolverContext $context, OneToManyAssociationField $field): string
    {
        if ($field->is(ReverseInherited::class) && $context->getContext()->considerInheritance()) {
            /** @var ReverseInherited $flag */
            $flag = $field->getFlag(ReverseInherited::class);

            return EntityDefinitionQueryHelper::escape($flag->getReversedPropertyName());
        }

        
QueryBuilder $query,
        Context $context
    ): void {
        $mapping = $field->getMappingDefinition();

        $versionCondition = '';
        if ($mapping->isVersionAware() && $definition->isVersionAware() && $field->is(CascadeDelete::class)) {
            $versionField = $definition->getEntityName() . '_version_id';
            $versionCondition = ' AND #alias#.' . $versionField . ' = #root#.version_id';
        }

        $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,
            
Home | Imprint | This part of the site doesn't use cookies.