Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/FactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public function withPersistMode(PersistMode $persistMode): static
return $clone;
}

/**
* @internal
*/
public function isPersisting(): bool
{
return $this->persistMode->isPersisting();
}

/**
* @internal
* @return self<T, TFactory>
Expand Down
13 changes: 10 additions & 3 deletions src/Persistence/PersistentObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,15 @@ protected function normalizeParameter(string $field, mixed $value): mixed
}

if ($value instanceof self) {
// TODO: Not know why, break some tests:
// $value = $value
// ->withPersistMode($value->persistMode())
// ->notRootFactory();
// So, store it instead
$isPersistingValue = $value->isPersisting();

$value = $value
->withPersistMode($this->persist)
->withPersistMode($this->persistMode())
->notRootFactory();

if (null !== $this->disabledDoctrineEventClasses) {
Expand All @@ -391,7 +398,7 @@ protected function normalizeParameter(string $field, mixed $value): mixed
$value = $value
->reuse(...$this->reusedObjects(), ...$value->reusedObjects())
->withPersistMode(
$this->isPersisting() ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
$this->isPersisting() && $isPersistingValue ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING
)
;

Expand Down Expand Up @@ -444,7 +451,7 @@ protected function normalizeCollection(string $field, FactoryCollection $collect

$inverseObjects = $collection
->reuse(...$this->reusedObjects())
->withPersistMode($this->isPersisting() ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING)
->withPersistMode($this->isPersisting() && $collection->isPersisting() ? PersistMode::NO_PERSIST_BUT_SCHEDULE_FOR_INSERT : PersistMode::WITHOUT_PERSISTING)
->create([$inverseField => $object]);

$inverseObjects = ProxyGenerator::unwrap($inverseObjects, withAutoRefresh: false);
Expand Down
Loading