Skip to content

Commit aada1c4

Browse files
authored
Merge pull request #792 from teohhanhui/iriconverter-relation-as-identifier-better-error-checking
Better error checking for relation used as identifier in IriConverter
2 parents 418211d + 6117fe9 commit aada1c4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Bridge/Symfony/Routing/IriConverter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ private function getIdentifiersFromItem($item) : array
134134
$propertyMetadata = $this->propertyMetadataFactory->create($relatedResourceClass, $relatedPropertyName);
135135

136136
if ($propertyMetadata->isIdentifier()) {
137+
if (isset($identifiers[$propertyName])) {
138+
throw new RuntimeException(sprintf('Composite identifiers not supported in "%s" through relation "%s" of "%s" used as identifier', $relatedResourceClass, $propertyName, $resourceClass));
139+
}
140+
137141
$identifiers[$propertyName] = $this->propertyAccessor->getValue($relatedItem, $relatedPropertyName);
138142
}
139143
}
140144

141-
if (empty($identifiers[$propertyName])) {
142-
throw new RuntimeException(sprintf('%s identifiers cannot be found', $resourceClass));
145+
if (!isset($identifiers[$propertyName])) {
146+
throw new RuntimeException(sprintf('No identifier found in "%s" through relation "%s" of "%s" used as identifier', $relatedResourceClass, $propertyName, $resourceClass));
143147
}
144148
}
145149

0 commit comments

Comments
 (0)