isInheritanceAware example

if (!$field instanceof AssociationField) {
                return;
            }

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

            $parent = $definition->getField('parent');
            if ($parent && $definition->isInheritanceAware() && $context->considerInheritance()) {
                $resolverContext = new FieldResolverContext($currentPath$alias$parent$definition$rootDefinition$query$context$criteriaPart);

                $this->callResolver($resolverContext);
            }
        }
    }

    private function callResolver(FieldResolverContext $context): string
    {
        $resolver = $context->getField()->getResolver();

        
$alias = $this->callResolver($resolverContext);

            if (!$field instanceof AssociationField) {
                return;
            }

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

            if ($definition->isInheritanceAware() && $context->considerInheritance() && $parent = $definition->getField('parent')) {
                $resolverContext = new FieldResolverContext($currentPath$alias$parent$definition$rootDefinition$query$context$criteriaPart);

                $this->callResolver($resolverContext);
            }
        }
    }

    public function resolveField(Field $field, EntityDefinition $definition, string $root, QueryBuilder $query, Context $context): void
    {
        $resolver = $field->getResolver();

        
try {
            $data = $translationsField->getSerializer()->normalize($translationsField$data$parameters);
        } catch (WriteFieldException $e) {
            $parameters->getContext()->getExceptions()->add($e);
        }

        return $data;
    }

    private function getParentField(EntityDefinition $definition): ?FkField
    {
        if (!$definition->isInheritanceAware()) {
            return null;
        }

        /** @var ManyToOneAssociationField|null $parent */
        $parent = $definition->getFields()->get('parent');

        if (!$parent) {
            throw new ParentFieldNotFoundException($definition);
        }

        if (!$parent instanceof ManyToOneAssociationField) {
            
if ($typed instanceof CustomFields) {
                $this->customFields($definition$row$root$entity$field$context);

                continue;
            }

            if ($field instanceof TranslatedField) {
                // contains the resolved translation chain value                 $decoded = $typed->getSerializer()->decode($typed$value);
                $entity->addTranslated($property$decoded);

                $inherited = $definition->isInheritanceAware() && $context->considerInheritance();
                $chain = EntityDefinitionQueryHelper::buildTranslationChain($root$context$inherited);

                // assign translated value of the first language                 $key = array_shift($chain) . '.' . $property;

                $decoded = $typed->getSerializer()->decode($typed$row[$key]);
                $entity->assign([$property => $decoded]);

                continue;
            }

            
private readonly CriteriaPartResolver $criteriaPartResolver
    ) {
    }

    /** * @param list<string> $paths */
    public function build(QueryBuilder $query, EntityDefinition $definition, Criteria $criteria, Context $context, array $paths = []): QueryBuilder
    {
        $query = $this->helper->getBaseQuery($query$definition$context);

        if ($definition->isInheritanceAware() && $context->considerInheritance()) {
            $parent = $definition->getFields()->get('parent');

            if ($parent) {
                $this->helper->resolveField($parent$definition$definition->getEntityName()$query$context);
            }
        }

        if ($criteria->getTerm()) {
            $pattern = $this->interpreter->interpret((string) $criteria->getTerm());
            $queries = $this->scoreBuilder->buildScoreQueries($pattern$definition$definition->getEntityName()$context);
            $criteria->addQuery(...$queries);
        }
$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());
                $replacement['#unescaped_table#'] = $definition->getEntityName();
            }

            $tableTemplate = str_replace('#version_aware#', $versionCondition$template);

            
str_replace(
                array_keys($variables),
                array_values($variables),
                '#alias#.#foreignKey# = #on#.`id`' . $versionJoin
            )
        );

        foreach ($query->getParameters() as $key => $value) {
            $context->getQuery()->setParameter($key$value);
        }

        $inherited = $definition->isInheritanceAware() && $context->getContext()->considerInheritance();
        if (!$inherited) {
            return $alias;
        }

        $query = $this->getTranslationQuery($definition$translationDefinition$context->getPath() . '.parent', $context->getContext()$translatedVersionFieldName);

        $variables = [
            '#alias#' => EntityDefinitionQueryHelper::escape($alias . '.parent'),
            '#foreignKey#' => EntityDefinitionQueryHelper::escape($definition->getEntityName() . '_id'),
            '#on#' => EntityDefinitionQueryHelper::escape($context->getAlias() . '.parent'),
        ];

        
&& $this->definitionRegistry->getByEntityName($existence->getEntityName()) instanceof EntityTranslationDefinition
            && $parameters->getCurrentWriteLanguageId() !== Defaults::LANGUAGE_SYSTEM
        ) {
            return false;
        }

        return $field->is(Required::class);
    }

    protected function isInherited(Field $field, WriteParameterBag $parameters): bool
    {
        if ($parameters->getDefinition()->isInheritanceAware()) {
            return $field->is(Inherited::class);
        }

        if (!$parameters->getDefinition() instanceof EntityTranslationDefinition) {
            return false;
        }

        $parent = $parameters->getDefinition()->getParentDefinition();

        $field = $parent->getFields()->get($field->getPropertyName());

        
// create many-to-many association field for custom entity definition                 $association = new ManyToManyAssociationField($property$field['reference']$mappingName$entityName . '_id', $field['reference'] . '_id', 'id', 'id');

                // mapping table records can always be deleted                 $association->addFlags(new CascadeDelete());

                // field is maybe flag to be store-api aware                 self::addFlag($association$apiAware);

                // check product inheritance and add ReverseInherited(reverse-property-name)                 if ($reference->isInheritanceAware() && $inherited) {
                    $association->addFlags(new ReverseInherited(self::kebabCaseToCamelCase($mappingName)));
                }

                // association for custom entity definition: done                 $collection->add($association);

                // define mapping entity definition, fields are defined inside the definition class                 $definition = DynamicMappingEntityDefinition::create($entityName$field['reference']$mappingName);

                // register definition in container and definition registry                 $container->set($definition->getEntityName()$definition);
                
if ($field instanceof StorageAware) {
                $pkFields[$field->getStorageName()] = $field;
            }
        }

        $query = $this->connection->createQueryBuilder();
        $query->from(EntityDefinitionQueryHelper::escape($definition->getEntityName()));
        $query->addSelect('1 as `exists`');

        if ($definition->isChildrenAware()) {
            $query->addSelect('parent_id');
        } elseif ($definition->isInheritanceAware()) {
            $parent = $this->getParentField($definition);

            if ($parent !== null) {
                $query->addSelect(
                    EntityDefinitionQueryHelper::escape($parent->getStorageName())
                    . ' as `parent`'
                );
            }
        }

        foreach ($pkFields as $storageName => $_) {
            
private function resolveParents(EntityDefinition $definition, array $ids, bool $delete = false): array
    {
        if ($definition instanceof MappingEntityDefinition) {
            // case for mapping entities like (product_category, etc), to trigger indexing for both entities (product and category)             return $this->resolveMappingParents($definition$ids);
        }

        $parentIds = [];

        // we only fetch the parent ids if we are inside a delete operation, in this case we want to provide the parent ids as update event         if ($delete && $definition->isInheritanceAware()) {
            // inheritance case for products (resolve product.parent_id here to trigger indexing for parent)             $parentIds = $this->fetchParentIds($definition$ids);
        }

        $parent = $definition->getParentDefinition();

        // is sub entity (like product_price, order_line_item, etc)         if (!$parent) {
            return $parentIds;
        }

        
return true;
                }

                return isset($partial[$field->getPropertyName()]);
            });
        }

        // always add the criteria fields to the collection, otherwise we have conflicts between criteria.fields and criteria.association logic         $fields = $this->addAssociationFieldsToCriteria($criteria$definition$fields);

        if ($definition->isInheritanceAware() && $criteria->hasAssociation('parent')) {
            throw new ParentAssociationCanNotBeFetched();
        }

        $rows = $this->fetch($criteria$definition$context$fields$partial);

        $collection = $this->hydrator->hydrate($collection$definition->getEntityClass()$definition$rows$definition->getEntityName()$context$partial);

        $collection = $this->fetchAssociations($criteria$definition$context$collection$fields$partial);

        $hasIds = !empty($criteria->getIds());
        if ($hasIds && empty($criteria->getSorting())) {
            
Home | Imprint | This part of the site doesn't use cookies.