@@ -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,13 @@ 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 ) {
165
+ $ singleKey = [] === $ options ->mapping ;
166
+
167
+ if (!$ mapping = $ options ->mapping ) {
156
168
$ mapping = $ request ->attributes ->keys ();
157
169
}
158
170
159
- if ($ mapping && \is_array ( $ mapping ) && array_is_list ($ mapping )) {
171
+ if ($ mapping && array_is_list ($ mapping )) {
160
172
$ mapping = array_combine ($ mapping , $ mapping );
161
173
}
162
174
@@ -176,13 +188,29 @@ private function getCriteria(Request $request, MapEntity $options, ObjectManager
176
188
177
189
$ criteria = [];
178
190
$ metadata = $ manager ->getClassMetadata ($ options ->class );
191
+ $ usedAttributes = [];
192
+
193
+ if ($ singleKey ) {
194
+ foreach ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [] as $ attribute ) {
195
+ unset($ mapping [$ attribute ]);
196
+ }
197
+ }
179
198
180
199
foreach ($ mapping as $ attribute => $ field ) {
181
200
if (!$ metadata ->hasField ($ field ) && (!$ metadata ->hasAssociation ($ field ) || !$ metadata ->isSingleValuedAssociation ($ field ))) {
182
201
continue ;
183
202
}
184
203
204
+ $ usedAttributes [] = $ attribute ;
185
205
$ criteria [$ field ] = $ request ->attributes ->get ($ attribute );
206
+
207
+ if ($ singleKey ) {
208
+ break ;
209
+ }
210
+ }
211
+
212
+ if ($ usedAttributes ) {
213
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], $ usedAttributes ));
186
214
}
187
215
188
216
if ($ options ->stripNull ) {
0 commit comments