Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Symfony/Routing/IriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ private function generateSymfonyRoute(object|string $resource, int $referenceTyp
{
$identifiers = $context['uri_variables'] ?? [];

foreach ($identifiers as $identifier) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, resources loaded with the ReadLinkParameterProvider are still objects, so we need to replace them with their identifier's value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should never reach this path with non scalar identifiers, this is a highly costly path in API Platform imo its inside the identifiers extractor that we should handle this.

Copy link
Author

@Geekimo Geekimo Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka In the getIdentifiersFromItem method, called at line 197 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, I need to take a look not sure what's happening.

if (is_object($identifier)) {
$identifiers = [
...$identifiers,
...$this->identifiersExtractor->getIdentifiersFromItem($identifier, $identifiersExtractorOperation, $context),
];
}
}

if (\is_object($resource)) {
try {
$identifiers = $this->identifiersExtractor->getIdentifiersFromItem($resource, $identifiersExtractorOperation, $context);
Expand Down
20 changes: 20 additions & 0 deletions tests/Functional/Parameters/LinkProviderParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,24 @@ public function testUriVariableHasDummy(): void
'dummy' => '/dummies/1',
]);
}

public function testCollectionIdIsCorrect(): void
{
$container = static::getContainer();
if ('mongodb' === $container->getParameter('kernel.environment')) {
$this->markTestSkipped();
}

$manager = $this->getManager();
$dummy = new Dummy();
$dummy->setName('hi');
$manager->persist($dummy);
$manager->flush();

self::createClient()->request('GET', '/link_parameter_provider_resources/'.$dummy->getId());

$this->assertJsonContains([
'@id' => '/link_parameter_provider_resources/1',
]);
}
}
Loading