Skip to content

Commit 269b052

Browse files
authored
Merge pull request #2905 from bastnic/feature/fix-child-iri
Generate iri for child related resources
2 parents 187ffc6 + fb86294 commit 269b052

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Serializer/AbstractItemNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array
533533
$resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className);
534534
$childContext = $this->createChildContext($context, $attribute, $format);
535535
$childContext['resource_class'] = $resourceClass;
536+
unset($childContext['iri']);
536537

537538
return $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext);
538539
}
@@ -545,6 +546,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array
545546
$resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className);
546547
$childContext = $this->createChildContext($context, $attribute, $format);
547548
$childContext['resource_class'] = $resourceClass;
549+
unset($childContext['iri']);
548550

549551
return $this->normalizeRelation($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext);
550552
}

tests/Serializer/AbstractItemNormalizerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ public function testNormalizeReadableLinks()
231231

232232
$serializerProphecy = $this->prophesize(SerializerInterface::class);
233233
$serializerProphecy->willImplement(NormalizerInterface::class);
234-
$serializerProphecy->normalize($relatedDummy, null, Argument::type('array'))->willReturn(['foo' => 'hello']);
234+
$relatedDummyChildContext = Argument::allOf(
235+
Argument::type('array'),
236+
Argument::withEntry('resource_class', RelatedDummy::class),
237+
Argument::not(Argument::withKey('iri'))
238+
);
239+
$serializerProphecy->normalize($relatedDummy, null, $relatedDummyChildContext)->willReturn(['foo' => 'hello']);
235240
$serializerProphecy->normalize(['foo' => 'hello'], null, Argument::type('array'))->willReturn(['foo' => 'hello']);
236241
$serializerProphecy->normalize([['foo' => 'hello']], null, Argument::type('array'))->willReturn([['foo' => 'hello']]);
237242

0 commit comments

Comments
 (0)