api-platform / api-platform/core

[Elasticsearch] Filtering on Nested Properties seems to not work

Aberta
#7,997 4 comentários 2 reações 0 responsáveis Ver no GitHub
Elasticsearch
Linguagem predominante
PHP
Estrelas
2.6k
Forks
980
Merge médio
2d 5h
PRs com merge (30d)
48

Descrição

**API Platform version(s) affected**: 2.5.3

**Description**
When filtering on a nested property in ES, we must provide the nested path. Function getNestedFieldPath() in FieldDatatypeTrait.php seems to always return null.

With the example given in your documentation, if we try this filter: /tweets?author.gender=male

author is an object so we enter in this condition:
```
if (
Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
&& null !== ($nextResourceClass = $type->getClassName())
&& $this->resourceClassResolver->isResourceClass($nextResourceClass)
) {
$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));

return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
}
```

getNestedFieldPath() is called recursively.

gender is the last element of the string, so when we do `$currentProperty = array_shift($properties);`, $properties is an empty array, so this part returns null:
```
if (!$properties) {
return null;
}
```

$nestedPath is null, so this line `return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";` returns null

This part seems to be never called:
```
if (
null !== ($type = $type->getCollectionValueType())
&& Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
&& null !== ($className = $type->getClassName())
&& $this->resourceClassResolver->isResourceClass($className)
) {
return $currentProperty;
}
```

Thanks

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.