groupFieldsPerEntity example

/** @var list<array{id: string, name: string, entity_name: string}> $customMediaFields */
        $customMediaFields = $this->connection->fetchAllAssociative(
            <<<'SQL' SELECT f.id, f.name, fsr.entity_name FROM custom_field f INNER JOIN custom_field_set fs ON (f.set_id = fs.id) INNER JOIN custom_field_set_relation fsr ON (fs.id = fsr.set_id) WHERE JSON_UNQUOTE(JSON_EXTRACT(f.config, '$.customFieldType')) = 'media' SQL
        );

        $fieldsPerEntity = $this->groupFieldsPerEntity($customMediaFields);

        $statements = [];
        foreach ($fieldsPerEntity as $entity => $fields) {
            $table = $this->getTableName((string) $entity);

            foreach ($fields as $field) {
                $statements[] = "SELECT JSON_UNQUOTE(JSON_EXTRACT({$table}.custom_fields, '$.{$field}')) as media_id FROM `{$table}` WHERE JSON_UNQUOTE(JSON_EXTRACT(`{$table}`.custom_fields, '$.{$field}')) IN (?)";
            }
        }

        if (\count($statements) === 0) {
            
Home | Imprint | This part of the site doesn't use cookies.