@@ -92,12 +92,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
92
92
$ caseSensitive = true ;
93
93
$ metadata = $ this ->getNestedMetadata ($ resourceClass , $ associations );
94
94
95
- if ($ metadata ->hasField ($ field )) {
96
- if ('id ' === $ field ) {
97
- $ values = array_map ([$ this , 'getIdFromValue ' ], $ values );
98
- }
95
+ $ doctrineTypeField = $ this ->getDoctrineFieldType ($ property , $ resourceClass );
96
+ $ values = array_map ([$ this , 'getIdFromValue ' ], $ values );
99
97
100
- if (!$ this ->hasValidValues ($ values , $ this ->getDoctrineFieldType ($ property , $ resourceClass ))) {
98
+ if ($ metadata ->hasField ($ field )) {
99
+ if (!$ this ->hasValidValues ($ values , $ doctrineTypeField )) {
101
100
$ this ->logger ->notice ('Invalid filter ignored ' , [
102
101
'exception ' => new InvalidArgumentException (sprintf ('Values for field "%s" are not valid according to the doctrine type. ' , $ field )),
103
102
]);
@@ -114,7 +113,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
114
113
}
115
114
116
115
if (1 === \count ($ values )) {
117
- $ this ->addWhereByStrategy ($ strategy , $ queryBuilder , $ queryNameGenerator , $ alias , $ field , $ values [0 ], $ caseSensitive );
116
+ $ this ->addWhereByStrategy ($ strategy , $ queryBuilder , $ queryNameGenerator , $ alias , $ field , $ doctrineTypeField , $ values [0 ], $ caseSensitive );
118
117
119
118
return ;
120
119
}
@@ -140,9 +139,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
140
139
return ;
141
140
}
142
141
143
- $ values = array_map ([$ this , 'getIdFromValue ' ], $ values );
144
142
$ associationFieldIdentifier = 'id ' ;
145
- $ doctrineTypeField = $ this ->getDoctrineFieldType ($ property , $ resourceClass );
146
143
147
144
if (null !== $ this ->identifiersExtractor ) {
148
145
$ associationResourceClass = $ metadata ->getAssociationTargetClass ($ field );
@@ -171,11 +168,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
171
168
if (1 === \count ($ values )) {
172
169
$ queryBuilder
173
170
->andWhere (sprintf ('%s.%s = :%s ' , $ associationAlias , $ associationField , $ valueParameter ))
174
- ->setParameter ($ valueParameter , $ values [0 ]);
171
+ ->setParameter ($ valueParameter , $ values [0 ], $ doctrineTypeField );
175
172
} else {
176
173
$ queryBuilder
177
174
->andWhere (sprintf ('%s.%s IN (:%s) ' , $ associationAlias , $ associationField , $ valueParameter ))
178
- ->setParameter ($ valueParameter , $ values );
175
+ ->setParameter ($ valueParameter , $ values, $ doctrineTypeField );
179
176
}
180
177
}
181
178
@@ -184,7 +181,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
184
181
*
185
182
* @throws InvalidArgumentException If strategy does not exist
186
183
*/
187
- protected function addWhereByStrategy (string $ strategy , QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ alias , string $ field , $ value , bool $ caseSensitive )
184
+ protected function addWhereByStrategy (string $ strategy , QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ alias , string $ field , $ fieldType , $ value , bool $ caseSensitive )
188
185
{
189
186
$ wrapCase = $ this ->createWrapCase ($ caseSensitive );
190
187
$ valueParameter = $ queryNameGenerator ->generateParameterName ($ field );
@@ -194,27 +191,27 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
194
191
case self ::STRATEGY_EXACT :
195
192
$ queryBuilder
196
193
->andWhere (sprintf ($ wrapCase ('%s.%s ' ).' = ' .$ wrapCase (':%s ' ), $ alias , $ field , $ valueParameter ))
197
- ->setParameter ($ valueParameter , $ value );
194
+ ->setParameter ($ valueParameter , $ value, $ fieldType );
198
195
break ;
199
196
case self ::STRATEGY_PARTIAL :
200
197
$ queryBuilder
201
198
->andWhere (sprintf ($ wrapCase ('%s.%s ' ).' LIKE ' .$ wrapCase ('CONCAT( \'%% \', :%s, \'%% \') ' ), $ alias , $ field , $ valueParameter ))
202
- ->setParameter ($ valueParameter , $ value );
199
+ ->setParameter ($ valueParameter , $ value, $ fieldType );
203
200
break ;
204
201
case self ::STRATEGY_START :
205
202
$ queryBuilder
206
203
->andWhere (sprintf ($ wrapCase ('%s.%s ' ).' LIKE ' .$ wrapCase ('CONCAT(:%s, \'%% \') ' ), $ alias , $ field , $ valueParameter ))
207
- ->setParameter ($ valueParameter , $ value );
204
+ ->setParameter ($ valueParameter , $ value, $ fieldType );
208
205
break ;
209
206
case self ::STRATEGY_END :
210
207
$ queryBuilder
211
208
->andWhere (sprintf ($ wrapCase ('%s.%s ' ).' LIKE ' .$ wrapCase ('CONCAT( \'%% \', :%s) ' ), $ alias , $ field , $ valueParameter ))
212
- ->setParameter ($ valueParameter , $ value );
209
+ ->setParameter ($ valueParameter , $ value, $ fieldType );
213
210
break ;
214
211
case self ::STRATEGY_WORD_START :
215
212
$ queryBuilder
216
213
->andWhere (sprintf ($ wrapCase ('%1$s.%2$s ' ).' LIKE ' .$ wrapCase ('CONCAT(:%3$s, \'%% \') ' ).' OR ' .$ wrapCase ('%1$s.%2$s ' ).' LIKE ' .$ wrapCase ('CONCAT( \'%% \', :%3$s, \'%% \') ' ), $ alias , $ field , $ valueParameter ))
217
- ->setParameter ($ valueParameter , $ value );
214
+ ->setParameter ($ valueParameter , $ value, $ fieldType );
218
215
break ;
219
216
default :
220
217
throw new InvalidArgumentException (sprintf ('strategy %s does not exist. ' , $ strategy ));
0 commit comments