@@ -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 ([] === $ options ->mapping && $ 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,18 @@ private function getIdentifier(Request $request, MapEntity $options, string $nam
140
146
}
141
147
142
148
if ($ request ->attributes ->has ($ name )) {
149
+ if ([] === $ options ->mapping ) {
150
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], [$ name ]));
151
+ }
152
+
143
153
return $ request ->attributes ->get ($ name ) ?? ($ options ->stripNull ? false : null );
144
154
}
145
155
146
156
if (!$ options ->id && $ request ->attributes ->has ('id ' )) {
157
+ if ([] === $ options ->mapping ) {
158
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], ['id ' ]));
159
+ }
160
+
147
161
return $ request ->attributes ->get ('id ' ) ?? ($ options ->stripNull ? false : null );
148
162
}
149
163
@@ -152,11 +166,13 @@ private function getIdentifier(Request $request, MapEntity $options, string $nam
152
166
153
167
private function getCriteria (Request $ request , MapEntity $ options , ObjectManager $ manager ): array
154
168
{
155
- if (null === $ mapping = $ options ->mapping ) {
169
+ $ singleKey = [] === $ options ->mapping ;
170
+
171
+ if (!$ mapping = $ options ->mapping ) {
156
172
$ mapping = $ request ->attributes ->keys ();
157
173
}
158
174
159
- if ($ mapping && \is_array ( $ mapping ) && array_is_list ($ mapping )) {
175
+ if ($ mapping && array_is_list ($ mapping )) {
160
176
$ mapping = array_combine ($ mapping , $ mapping );
161
177
}
162
178
@@ -177,12 +193,23 @@ private function getCriteria(Request $request, MapEntity $options, ObjectManager
177
193
$ criteria = [];
178
194
$ metadata = $ manager ->getClassMetadata ($ options ->class );
179
195
196
+ if ($ singleKey ) {
197
+ foreach ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [] as $ attribute ) {
198
+ unset($ mapping [$ attribute ]);
199
+ }
200
+ }
201
+
180
202
foreach ($ mapping as $ attribute => $ field ) {
181
203
if (!$ metadata ->hasField ($ field ) && (!$ metadata ->hasAssociation ($ field ) || !$ metadata ->isSingleValuedAssociation ($ field ))) {
182
204
continue ;
183
205
}
184
206
185
207
$ criteria [$ field ] = $ request ->attributes ->get ($ attribute );
208
+
209
+ if ($ singleKey ) {
210
+ $ request ->attributes ->set ('_entity_used_attributes ' , array_merge ($ request ->attributes ->get ('_entity_used_attributes ' ) ?? [], [$ attribute ]));
211
+ break ;
212
+ }
186
213
}
187
214
188
215
if ($ options ->stripNull ) {
0 commit comments