@@ -291,10 +291,15 @@ protected function normalizeParameter(string $field, mixed $value): mixed
291
291
if ($ inversedRelationshipMetadata && !$ inversedRelationshipMetadata ->isCollection ) {
292
292
$ inverseField = $ inversedRelationshipMetadata ->inverseField ;
293
293
294
- // we need to handle the circular dependency involved by inversed one-to-one relationship:
295
- // a placeholder object is used, which will be replaced by the real object, after its instantiation
296
- $ inversedObject = $ value ->withPersistMode (PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT )
297
- ->create ([$ inverseField => $ placeholder = (new \ReflectionClass (static ::class ()))->newInstanceWithoutConstructor ()]);
294
+ $ inversedObject = $ value ->withPersistMode (
295
+ $ this ->isPersisting () ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
296
+ )
297
+
298
+ // we need to handle the circular dependency involved by inversed one-to-one relationship:
299
+ // a placeholder object is used, which will be replaced by the real object, after its instantiation
300
+ ->create ([
301
+ $ inverseField => $ placeholder = (new \ReflectionClass (static ::class ()))->newInstanceWithoutConstructor (),
302
+ ]);
298
303
299
304
$ inversedObject = unproxy ($ inversedObject , withAutoRefresh: false );
300
305
@@ -312,7 +317,7 @@ protected function normalizeParameter(string $field, mixed $value): mixed
312
317
313
318
protected function normalizeCollection (string $ field , FactoryCollection $ collection ): array
314
319
{
315
- if (!$ this -> isPersisting () || !$ collection ->factory instanceof self) {
320
+ if (!Configuration:: instance ()-> isPersistenceAvailable () || !$ collection ->factory instanceof self) {
316
321
return parent ::normalizeCollection ($ field , $ collection );
317
322
}
318
323
@@ -321,10 +326,13 @@ protected function normalizeCollection(string $field, FactoryCollection $collect
321
326
$ inverseRelationshipMetadata = $ pm ->inverseRelationshipMetadata (static ::class (), $ collection ->factory ::class (), $ field );
322
327
323
328
if ($ inverseRelationshipMetadata && $ inverseRelationshipMetadata ->isCollection ) {
324
- $ this ->tempAfterInstantiate [] = static function (object $ object ) use ($ collection , $ inverseRelationshipMetadata , $ field ) {
329
+ $ this ->tempAfterInstantiate [] = function (object $ object ) use ($ collection , $ inverseRelationshipMetadata , $ field ) {
325
330
$ inverseField = $ inverseRelationshipMetadata ->inverseField ;
326
331
327
- $ inverseObjects = $ collection ->withPersistMode (PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT )->create ([$ inverseField => $ object ]);
332
+ $ inverseObjects = $ collection ->withPersistMode (
333
+ $ this ->isPersisting () ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
334
+ )
335
+ ->create ([$ inverseField => $ object ]);
328
336
329
337
$ inverseObjects = unproxy ($ inverseObjects , withAutoRefresh: false );
330
338
0 commit comments