Skip to content

Commit 561bc89

Browse files
committed
fix(elasticsearch): support additional nesting within collections (api-platform#5642)
1 parent 5ca9da5 commit 561bc89

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Elasticsearch/Util/FieldDatatypeTrait.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
8282
&& null !== ($className = $type->getClassName())
8383
&& $this->resourceClassResolver->isResourceClass($className)
8484
) {
85-
return $currentProperty;
85+
$nestedPath = $this->getNestedFieldPath($className, implode('.', $properties));
86+
87+
return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";
8688
}
8789

8890
return null;

tests/Elasticsearch/Util/FieldDatatypeTraitTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function testGetNestedFieldPath(): void
3636
self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz'));
3737
}
3838

39+
public function testGetNestedFieldInNestedCollection(): void
40+
{
41+
$fieldDatatype = $this->getValidFieldDatatype();
42+
43+
self::assertSame('bar.foo', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo.baz'));
44+
self::assertSame('bar', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo'));
45+
self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz'));
46+
}
47+
3948
public function testGetNestedFieldPathWithPropertyNotFound(): void
4049
{
4150
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);

0 commit comments

Comments
 (0)