Skip to content

Commit ef0ee64

Browse files
authoredSep 2, 2024··
fix(doctrine): use parameter.property for filter value (#6572)
1 parent 50d2ca8 commit ef0ee64

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed
 

‎src/Doctrine/Common/ParameterValueExtractorTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait ParameterValueExtractorTrait
2222
*/
2323
private function extractParameterValue(Parameter $parameter, mixed $value): array
2424
{
25-
$key = $parameter->getKey();
25+
$key = $parameter->getProperty() ?? $parameter->getKey();
2626
if (!str_contains($key, ':property')) {
2727
return [$key => $value];
2828
}

‎tests/Fixtures/TestBundle/Entity/SearchFilterParameter.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
uriTemplate: 'search_filter_parameter{._format}',
2626
parameters: [
2727
'foo' => new QueryParameter(filter: 'app_search_filter_via_parameter'),
28+
'fooAlias' => new QueryParameter(filter: 'app_search_filter_via_parameter', property: 'foo'),
2829
'order[:property]' => new QueryParameter(filter: 'app_search_filter_via_parameter.order_filter'),
2930

3031
'searchPartial[:property]' => new QueryParameter(filter: 'app_search_filter_partial'),

‎tests/Functional/Parameters/DoctrineTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ public function testDoctrineEntitySearchFilter(): void
3333
$this->assertEquals('bar', $a['hydra:member'][1]['foo']);
3434

3535
$this->assertArraySubset(['hydra:search' => [
36-
'hydra:template' => \sprintf('/%s{?foo,order[order[id]],order[order[foo]],searchPartial[foo],searchExact[foo],searchOnTextAndDate[foo],searchOnTextAndDate[createdAt][before],searchOnTextAndDate[createdAt][strictly_before],searchOnTextAndDate[createdAt][after],searchOnTextAndDate[createdAt][strictly_after],q}', $route),
36+
'hydra:template' => \sprintf('/%s{?foo,fooAlias,order[order[id]],order[order[foo]],searchPartial[foo],searchExact[foo],searchOnTextAndDate[foo],searchOnTextAndDate[createdAt][before],searchOnTextAndDate[createdAt][strictly_before],searchOnTextAndDate[createdAt][after],searchOnTextAndDate[createdAt][strictly_after],q}', $route),
3737
'hydra:mapping' => [
3838
['@type' => 'IriTemplateMapping', 'variable' => 'foo', 'property' => 'foo'],
3939
],
4040
]], $a);
4141

42+
$response = self::createClient()->request('GET', $route.'?fooAlias=baz');
43+
$a = $response->toArray();
44+
$this->assertCount(1, $a['hydra:member']);
45+
$this->assertEquals('baz', $a['hydra:member'][0]['foo']);
46+
4247
$response = self::createClient()->request('GET', $route.'?order[foo]=asc');
4348
$this->assertEquals($response->toArray()['hydra:member'][0]['foo'], 'bar');
4449
$response = self::createClient()->request('GET', $route.'?order[foo]=desc');

0 commit comments

Comments
 (0)
Please sign in to comment.