getByStorageName example


        if (!$context->getDefinition()->isVersionAware()) {
            return '';
        }
        if (!$field->is(CascadeDelete::class)) {
            return '';
        }

        $fkVersionId = $context->getDefinition()->getEntityName() . '_version_id';

        $reference = $field->getReferenceDefinition();
        if ($reference->getFields()->getByStorageName($fkVersionId)) {
            return ' AND #root#.version_id = #alias#.' . $fkVersionId;
        }

        $fkVersionId = \substr($field->getReferenceField(), 0, -3) . '_version_id';
        if ($reference->getFields()->getByStorageName($fkVersionId)) {
            return ' AND #root#.version_id = #alias#.' . $fkVersionId;
        }

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

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

                return $field->getStorageName() === $association->getReferenceField() && $field->getReferenceDefinition() === $definition;
            }
        )->first();

        $foreignKey = $reference->getFields()->getByStorageName($association->getReferenceField());

        if ($foreignKey instanceof Field && !$foreignKey instanceof FkField) {
            $isGeneric = \in_array(
                $reference->getEntityName() . '.' . $foreignKey->getPropertyName(),
                self::GENERIC_FK_FIELDS,
                true
            );

            if (!$isGeneric) {
                $associationViolations[$definition->getClass()][] = sprintf(
                    'Missing reference foreign key for column %s for definition association %s.%s',
                    
$primaryKey = $command->getPrimaryKey();

        sort($primaryKey);

        $decodedPrimaryKey = [];
        foreach ($primaryKey as $fieldValue) {
            /** @var string|false $fieldName */
            $fieldName = array_search($fieldValue$command->getPrimaryKey(), true);
            /** @var Field|null $field */
            $field = null;
            if ($fieldName) {
                $field = $senderIdentification->getFields()->get($fieldName) ?? $senderIdentification->getFields()->getByStorageName($fieldName);
            }
            $decodedPrimaryKey[] = $field ? $field->getSerializer()->decode($field$fieldValue) : $fieldValue;
        }

        $hash = $senderIdentification->getEntityName() . ':' . md5(json_encode($decodedPrimaryKey, \JSON_THROW_ON_ERROR));

        $this->commands[$senderIdentification->getEntityName()][] = $command;

        $this->entityCommands[$hash][] = $command;
        $this->definitions[$senderIdentification->getEntityName()] = $senderIdentification;
    }

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

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

        if (!$parent instanceof ManyToOneAssociationField) {
            throw new InvalidParentAssociationException($definition$parent);
        }

        $fk = $definition->getFields()->getByStorageName($parent->getStorageName());

        if (!$fk) {
            throw new CanNotFindParentStorageFieldException($definition);
        }
        if (!$fk instanceof FkField) {
            throw new ParentFieldForeignKeyConstraintMissingException($definition$fk);
        }

        return $fk;
    }

    
// 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,
            ];
$key = $field->getPropertyName();
        $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

    private function loadOneToManyWithoutPagination(
        EntityDefinition $definition,
        OneToManyAssociationField $association,
        Context $context,
        EntityCollection $collection,
        Criteria $fieldCriteria,
        array $partial
    ): void {
        $ref = $association->getReferenceDefinition()->getFields()->getByStorageName(
            $association->getReferenceField()
        );

        \assert($ref instanceof Field);

        $propertyName = $ref->getPropertyName();
        if ($association instanceof ChildrenAssociationField) {
            $propertyName = 'parentId';
        }

        // build orm property accessor to add field sortings and conditions `customer_address.customerId`
return $row[$accessor] ?? null;
    }

    protected function getManyToOneProperty(AssociationField $field): string
    {
        $key = $field->getReferenceDefinition()->getEntityName() . '.' . $field->getReferenceField();
        if (isset(self::$manyToOne[$key])) {
            return self::$manyToOne[$key];
        }

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

        if ($reference === null) {
            throw new \RuntimeException(sprintf(
                'Can not find field by storage name %s in definition %s',
                $field->getReferenceField(),
                $field->getReferenceDefinition()->getEntityName()
            ));
        }

        
/* * Updates for entities with attributes are split into two commands: an UpdateCommand and a JsonUpdateCommand. * We need to merge the payloads here. */
            foreach ($jsonUpdateCommands as $uniqueId => $command) {
                $payload = [];
                if (isset($writeResults[$uniqueId])) {
                    $payload = $writeResults[$uniqueId]->getPayload();
                }

                $field = $command->getDefinition()->getFields()->getByStorageName($command->getStorageName());

                if (!$field instanceof Field) {
                    throw new \RuntimeException(sprintf('Field by storage name %s not found', $command->getStorageName()));
                }

                $decodedPayload = $field->getSerializer()->decode(
                    $field,
                    json_encode($command->getPayload(), \JSON_PRESERVE_ZERO_FRACTION | \JSON_THROW_ON_ERROR)
                );
                $mergedPayload = array_merge($payload[$field->getPropertyName() => $decodedPayload]);

                
$referenceDefinition,
                $path . '/' . $languageId
            );

            $data[$key] = [
                $languageId => $this->writeExtractor->normalizeSingle($referenceDefinition[]$clonedParams),
            ];

            return $data;
        }

        $languageField = $referenceDefinition->getFields()->getByStorageName($field->getLanguageField());
        if ($languageField === null) {
            throw new \RuntimeException(
                sprintf(
                    'Could not find language field "%s" in definition "%s"',
                    $field->getLanguageField(),
                    $referenceDefinition::class
                D
            );
        }

        $languagePropName = $languageField->getPropertyName();

        
if (!$field->is(Inherited::class)) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());
        }

        if (!$context->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());
        }

        $inherited = EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());

        $fk = $definition->getFields()->getByStorageName($field->getStorageName());

        if (!$fk) {
            throw new \RuntimeException(sprintf('Can not find foreign key for table column %s.%s', $definition->getEntityName()$field->getStorageName()));
        }

        if ($fk instanceof IdField && $field->is(PrimaryKey::class)) {
            return $inherited;
        }

        if ($fk instanceof FkField && $field->is(Required::class)) {
            return sprintf(
                


        // only foreign key provided? entity should only be linked         /*e.g [ categories => [ ['id' => {id}], ['id' => {id}] ] ] */
        $fk = $referencedDefinition->getFields()->getByStorageName(
            $association->getStorageName()
        );

        if (!$fk) {
            @trigger_error(sprintf('Foreign key for association %s not found', $association->getPropertyName()));

            $data['versionId'] = Defaults::LIVE_VERSION;

            return [$association->getPropertyName() => $data];
        }

        

    public function __construct(private readonly WriteCommandExtractor $writeExtractor)
    {
    }

    public function normalize(Field $field, array $data, WriteParameterBag $parameters): array
    {
        if (!$field instanceof ManyToOneAssociationField) {
            throw DataAbstractionLayerException::invalidSerializerField(ManyToOneAssociationField::class$field);
        }

        $referenceField = $field->getReferenceDefinition()->getFields()->getByStorageName($field->getReferenceField());
        if ($referenceField === null) {
            throw new \RuntimeException(
                sprintf(
                    'Could not find reference field "%s" from definition "%s"',
                    $field->getReferenceField(),
                    $field->getReferenceDefinition()::class
                D
            );
        }
        $key = $field->getPropertyName();
        $value = $data[$key] ?? null;
        
$definition = $field->getReferenceDefinition();

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

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

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

            if ($fkey === null) {
                continue;
            }

            $criteria->addFilter(
                new EqualsFilter(sprintf('media.%s.%s', $field->getPropertyName()$fkey->getPropertyName()), null)
            );
        }

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