@@ -217,7 +217,7 @@ public function create(callable|array $attributes = []): object
217
217
throw new \LogicException ('Persistence cannot be used in unit tests. ' );
218
218
}
219
219
220
- $ configuration ->persistence ()->save ( $ object );
220
+ $ configuration ->persistence ()->saveAll ( );
221
221
222
222
return $ object ;
223
223
}
@@ -293,25 +293,23 @@ protected function normalizeParameter(string $field, mixed $value): mixed
293
293
if ($ inversedRelationshipMetadata && !$ inversedRelationshipMetadata ->isCollection ) {
294
294
$ inverseField = $ inversedRelationshipMetadata ->inverseField ;
295
295
296
- $ inversedObject = $ value ->withPersistMode (
297
- $ this ->isPersisting () ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
298
- )
299
- ->notRootFactory ()
296
+ // we need to handle the circular dependency involved by inversed one-to-one relationship:
297
+ // a placeholder object is used, which will be replaced by the real object, after its instantiation
298
+ $ inverseObjectPlaceholder = (new \ReflectionClass ($ value ::class ()))->newInstanceWithoutConstructor ();
300
299
301
- // we need to handle the circular dependency involved by inversed one-to-one relationship:
302
- // a placeholder object is used, which will be replaced by the real object, after its instantiation
303
- ->create ([
304
- $ inverseField => $ placeholder = (new \ReflectionClass (static ::class ()))->newInstanceWithoutConstructor (),
305
- ]);
300
+ $ this ->tempAfterInstantiate [] = function (object $ object ) use ($ value , $ inverseField , $ field ) {
301
+ $ inverseObject = $ value ->withPersistMode (
302
+ $ this ->isPersisting () ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
303
+ )
304
+ ->notRootFactory ()
305
+ ->create ([$ inverseField => $ object ]);
306
306
307
- $ inversedObject = unproxy ($ inversedObject , withAutoRefresh: false );
307
+ $ inverseObject = unproxy ($ inverseObject , withAutoRefresh: false );
308
308
309
- $ this ->tempAfterInstantiate [] = static function (object $ object ) use ($ inversedObject , $ inverseField , $ pm , $ placeholder ) {
310
- $ pm ->forget ($ placeholder );
311
- set ($ inversedObject , $ inverseField , $ object );
309
+ set ($ object , $ field , $ inverseObject );
312
310
};
313
311
314
- return $ inversedObject ;
312
+ return $ inverseObjectPlaceholder ;
315
313
} else {
316
314
$ value = $ value ->notRootFactory ();
317
315
}
@@ -384,6 +382,8 @@ protected function normalizeObject(object $object): object
384
382
385
383
if (!$ persistenceManager ->isPersisted ($ object )) {
386
384
$ persistenceManager ->scheduleForInsert ($ object );
385
+
386
+ return $ object ;
387
387
}
388
388
389
389
try {
0 commit comments