addEntity example

$serialized->addLink('self', $self);
        $serialized->merge($entity);

        // add included entities         $this->serializeRelationships($fields$serialized$entity$result);

        $this->addExtensions($fields$serialized$entity$result);

        if ($isRelationship) {
            $result->addIncluded($serialized);
        } else {
            $result->addEntity($serialized);
        }
    }

    protected function serializeRelationships(ResponseFields $fields, Record $record, Entity $entity, JsonApiEncodingResult $result): void
    {
        $relationships = $record->getRelationships();

        foreach ($relationships as $propertyName => &$relationship) {
            $relationship['links']['related'] = $record->getLink('self') . '/' . $this->camelCaseToSnailCase($propertyName);

            try {
                
$query = $this->connection->createQueryBuilder();
        $escaped = EntityDefinitionQueryHelper::escape($definition->getEntityName());
        $column = EntityDefinitionQueryHelper::escape($column);
        $query->from($escaped);
        $query->select('id', 'parent_id');
        $query->andWhere($column . ' IN (:ids)');
        $query->setParameter('ids', $ids, ArrayParameterType::STRING);
        $this->makeQueryVersionAware($definition, Uuid::fromHexToBytes($context->getVersionId())$query);

        $fetchedIds = [];
        foreach ($query->executeQuery()->fetchAllAssociative() as $entity) {
            $bag->addEntity($entity['id']$entity);
            $fetchedIds[$entity['id']] = $entity['id'];
        }

        return $fetchedIds;
    }

    /** * @param array<string> $updateIds */
    private function updateLevelRecursively(array $updateIds, EntityDefinition $definition, Context $context, TreeUpdaterBag $bag): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.