@@ -123,15 +123,21 @@ private function getIdentifier(Request $request, MapEntity $options, string $nam
123
123
{
124
124
if (\is_array ($ options ->id )) {
125
125
$ id = [];
126
+ $ usedAttributes = [];
126
127
foreach ($ options ->id as $ field ) {
127
128
// Convert "%s_uuid" to "foobar_uuid"
128
129
if (str_contains ($ field , '%s ' )) {
129
130
$ field = sprintf ($ field , $ name );
130
131
}
131
132
133
+ $ usedAttributes [] = $ field ;
132
134
$ id [$ field ] = $ request ->attributes ->get ($ field );
133
135
}
134
136
137
+ if ($ usedAttributes ) {
138
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], $ usedAttributes ));
139
+ }
140
+
135
141
return $ id ;
136
142
}
137
143
@@ -140,10 +146,14 @@ private function getIdentifier(Request $request, MapEntity $options, string $nam
140
146
}
141
147
142
148
if ($ request ->attributes ->has ($ name )) {
149
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], [$ name ]));
150
+
143
151
return $ request ->attributes ->get ($ name ) ?? ($ options ->stripNull ? false : null );
144
152
}
145
153
146
154
if (!$ options ->id && $ request ->attributes ->has ('id ' )) {
155
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], ['id ' ]));
156
+
147
157
return $ request ->attributes ->get ('id ' ) ?? ($ options ->stripNull ? false : null );
148
158
}
149
159
@@ -152,11 +162,15 @@ private function getIdentifier(Request $request, MapEntity $options, string $nam
152
162
153
163
private function getCriteria (Request $ request , MapEntity $ options , ObjectManager $ manager ): array
154
164
{
155
- if (null === $ mapping = $ options ->mapping ) {
156
- $ mapping = $ request ->attributes ->keys ();
165
+ $ singleKey = [] === $ options ->mapping ;
166
+
167
+ if (!$ mapping = $ options ->mapping ) {
168
+ $ mapping = $ request ->attributes ->all ();
169
+ unset($ mapping ['_entity_used_attributes ' ]);
170
+ $ mapping = array_keys ($ mapping );
157
171
}
158
172
159
- if ($ mapping && \is_array ( $ mapping ) && array_is_list ($ mapping )) {
173
+ if ($ mapping && array_is_list ($ mapping )) {
160
174
$ mapping = array_combine ($ mapping , $ mapping );
161
175
}
162
176
@@ -176,13 +190,29 @@ private function getCriteria(Request $request, MapEntity $options, ObjectManager
176
190
177
191
$ criteria = [];
178
192
$ metadata = $ manager ->getClassMetadata ($ options ->class );
193
+ $ usedAttributes = [];
194
+
195
+ if ($ singleKey ) {
196
+ foreach ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [] as $ attribute ) {
197
+ unset($ mapping [$ attribute ]);
198
+ }
199
+ }
179
200
180
201
foreach ($ mapping as $ attribute => $ field ) {
181
202
if (!$ metadata ->hasField ($ field ) && (!$ metadata ->hasAssociation ($ field ) || !$ metadata ->isSingleValuedAssociation ($ field ))) {
182
203
continue ;
183
204
}
184
205
206
+ $ usedAttributes [] = $ attribute ;
185
207
$ criteria [$ field ] = $ request ->attributes ->get ($ attribute );
208
+
209
+ if ($ singleKey ) {
210
+ break ;
211
+ }
212
+ }
213
+
214
+ if ($ usedAttributes ) {
215
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], $ usedAttributes ));
186
216
}
187
217
188
218
if ($ options ->stripNull ) {
0 commit comments