getReferenceDefinition example



    protected function getResolverClass(): ?string
    {
        return ManyToManyAssociationFieldResolver::class;
    }

    protected function compileLazy(): void
    {
        parent::compileLazy();

        $this->mappingDefinition = $this->getReferenceDefinition();

        \assert($this->registry !== null, 'registry could not be null, because the `compile` method must be called first');
        $this->toManyDefinition = $this->registry->getByClassOrEntityName($this->toManyDefinitionClass);
        $this->toManyDefinitionClass = $this->toManyDefinition->getClass();
    }
}
$parameters = [
            '#source#' => $source,
            '#alias#' => EntityDefinitionQueryHelper::escape($alias),
            '#reference_column#' => $referenceColumn,
            '#root#' => EntityDefinitionQueryHelper::escape($context->getAlias()),
        ];

        $versionWhere = $this->buildVersionWhere($context$field);

        $context->getQuery()->leftJoin(
            EntityDefinitionQueryHelper::escape($context->getAlias()),
            EntityDefinitionQueryHelper::escape($field->getReferenceDefinition()->getEntityName()),
            EntityDefinitionQueryHelper::escape($alias),
            str_replace(
                array_keys($parameters),
                array_values($parameters),
                '#source# = #alias#.#reference_column#' . $versionWhere
            )
        );

        return $alias;
    }

    
continue;
            }

            $fkFields = $definition->getFields()->filterInstance(FkField::class);

            if ($fkFields->count() <= 0) {
                continue;
            }

            /** @var FkField $field */
            foreach ($fkFields as $field) {
                $reference = $field->getReferenceDefinition()->getEntityName();

                $mappings[$reference] = array_merge($mappings[$reference] ?? []array_column($ids$field->getPropertyName()));
            }
        }

        return $mappings;
    }

    public function addParentResults(array $writeResults, array $parents): array
    {
        foreach ($parents as $entity => $primaryKeys) {
            
$queries = array_merge(
                    $queries,
                    $this->buildScoreQueries($term$field->getToManyReferenceDefinition()$select$context$ranking)
                );

                continue;
            }

            if ($field instanceof AssociationField) {
                $queries = array_merge(
                    $queries,
                    $this->buildScoreQueries($term$field->getReferenceDefinition()$select$context$ranking)
                );

                continue;
            }

            $queries[] = new ScoreQuery(
                new EqualsFilter($select$term->getOriginal()->getTerm()),
                $ranking * $term->getOriginal()->getScore()
            );

            $queries[] = new ScoreQuery(
                

    private function validateCriteriaAssociation(EntityDefinition $definition, array $associations, Context $context): void
    {
        /** @var Criteria $criteria */
        foreach ($associations as $associationName => $criteria) {
            $field = $definition->getField($associationName);
            if (!$field instanceof AssociationField) {
                continue;
            }

            $associationDefinition = $field->getReferenceDefinition();
            $readProtection = $associationDefinition->getProtections()->get(ReadProtection::class);
            if ($readProtection && !$readProtection->isAllowed($context->getScope())) {
                throw new AccessDeniedHttpException(
                    sprintf(
                        'Read access to nested association "%s" on entity "%s" not allowed for scope "%s".',
                        $associationName,
                        $definition->getEntityName(),
                        $context->getScope()
                    )
                );
            }

            
while (\count($parts) > 0) {
            $part = array_shift($parts);
            $value = $fields->get($part);

            if ($value === null && !$smartDetect) {
                break;
            }

            $smartDetect = false;

            if ($value instanceof AssociationField) {
                $fields = $value->getReferenceDefinition()->getFields();
            }
        }

        return $value;
    }

    protected function resolveCriteriaForLazyLoadedRelations(
        EntityResolverContext $resolverContext,
        FieldConfig $config
    ): ?Criteria {
        $field = $this->resolveDefinitionField($resolverContext->getDefinition()$config->getStringValue());
        


    final public function getTranslationDefinition(): ?EntityDefinition
    {
        // value is initialized from this method         $this->getFields();

        if ($this->translationField === null) {
            return null;
        }

        return $this->translationField->getReferenceDefinition();
    }

    final public function getTranslationField(): ?TranslationsAssociationField
    {
        // value is initialized from this method         $this->getFields();

        return $this->translationField;
    }

    final public function hasAutoIncrement(): bool
    {
/** @var ApiAware|null $flag */
            $flag = $field->getFlag(ApiAware::class);

            if ($flag === null || !$flag->isBaseUrlAllowed($result->getBaseUrl())) {
                continue;
            }

            if ($field instanceof AssociationField) {
                $isSingle = $field instanceof ManyToOneAssociationField || $field instanceof OneToOneAssociationField;

                $reference = $field->getReferenceDefinition();
                if ($field instanceof ManyToManyAssociationField) {
                    $reference = $field->getToManyReferenceDefinition();
                }

                if ($field->is(Extension::class)) {
                    $serialized->addExtension(
                        $propertyName,
                        [
                            'tmp' => [
                                'definition' => $reference,
                            ],
                            
throw new \InvalidArgumentException('Expected *ToOneField');
        }

        if ($record === null) {
            return null;
        }

        if ($record instanceof Struct) {
            $record = $record->jsonSerialize();
        }

        $definition = $toOne->getReferenceDefinition();
        $entitySerializer = $this->serializerRegistry->getEntity($definition->getEntityName());

        $result = $entitySerializer->serialize($config$definition$record);
        if ($record !== null) {
            yield $toOne->getPropertyName() => iterator_to_array($result);
        }
    }

    /** * @param mixed $records * * @return mixed */
$value = $data[$key] ?? null;
        if ($value === null) {
            return $data;
        }

        if (!\is_array($value)) {
            throw new ExpectedArrayException($parameters->getPath());
        }

        /** @var Field $keyField */
        $keyField = $parameters->getDefinition()->getFields()->getByStorageName($field->getStorageName());
        $reference = $field->getReferenceDefinition();

        if ($keyField instanceof FkField) {
            $referenceField = $field->getReferenceField();
            $pkField = $reference->getFields()->getByStorageName($referenceField);
            if ($pkField === null) {
                throw new \RuntimeException(
                    sprintf(
                        'Could not find reference field "%s" in definition "%s"',
                        $referenceField,
                        $reference::class
                    D
                );
foreach ($payload['associations'] as $propertyName => $association) {
                if (!\is_array($association)) {
                    continue;
                }

                $field = $definition->getFields()->get($propertyName);

                if (!$field instanceof AssociationField) {
                    throw new AssociationNotFoundException((string) $propertyName);
                }

                $ref = $field->getReferenceDefinition();
                if ($field instanceof ManyToManyAssociationField) {
                    $ref = $field->getToManyReferenceDefinition();
                }

                $nested = $criteria->getAssociation($propertyName);

                $this->parse($association$nested$ref$context, null);

                if ($field instanceof TranslationsAssociationField) {
                    $nested->setLimit(null);
                }
            }
$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),
                array_values($parameters),
                '#source# = #alias#.#reference_column# AND #alias#.route_name = :' . $routeParamKey . ' AND #alias#.is_deleted = 0'
            )
        );

        $context->getQuery()->setParameter($routeParamKey$field->getRouteName());

        
$filter->setResolved(self::escape($alias) . '.id IS NOT NULL');
        }

        $query->andWhere(implode(' AND ', $parsed->getWheres()));
    }

    private function createNestedQuery(AssociationField $field, EntityDefinition $definition, Context $context): QueryBuilder
    {
        $query = new QueryBuilder($this->connection);

        if ($field instanceof OneToManyAssociationField) {
            $reference = $field->getReferenceDefinition();
            $alias = $definition->getEntityName() . '.' . $field->getPropertyName();

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

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

            return $query;
        }
$criteria = new Criteria();

        foreach ($this->mediaRepo->getDefinition()->getFields() as $field) {
            if (!$field instanceof AssociationField) {
                continue;
            }

            if (!\in_array($field::class, self::VALID_ASSOCIATIONS, true)) {
                continue;
            }

            $definition = $field->getReferenceDefinition();

            if ($field instanceof ManyToManyAssociationField) {
                $definition = $field->getToManyReferenceDefinition();
            }

            if ($this->isInsideTopLevelDomain(MediaDefinition::ENTITY_NAME, $definition)) {
                continue;
            }

            $fkey = $definition->getFields()->getByStorageName($field->getReferenceField());

            


        $definition = $this->registry->getByEntityName($entity);

        foreach ($criteria->getAssociations() as $field => $nested) {
            $association = $definition->getField($field);

            if (!$association instanceof AssociationField) {
                throw new AssociationNotFoundException($field);
            }

            $reference = $association->getReferenceDefinition()->getEntityName();
            if ($association instanceof ManyToManyAssociationField) {
                $reference = $association->getToManyReferenceDefinition()->getEntityName();
            }

            $missing = array_merge($missing$this->validate($reference$nested$context));
        }

        foreach ($criteria->getAllFields() as $accessor) {
            $fields = EntityDefinitionQueryHelper::getFieldsOfAccessor($definition$accessor);

            foreach ($fields as $field) {
                
Home | Imprint | This part of the site doesn't use cookies.