Do I have to manually compute the changeset of new related entities in onFlush?
- Dominant language
- PHP
- Stars
- 10.2k
- Forks
- 2.5k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 34
Description
Inside the `onFlush` listener, we deep copy an existing entity including its relations and the relations of the related entities. The hierarchy looks something like this
```
ParentEntity
-> SomeChildEntity
-> OtherChildEntities (ArrayCollection/PersistantCollection)
-> ChildrenOfChildEntities (ArrayCollection/PersistantCollection)
```
So all entities inside this hierarchy are new for the copied entity. I was hoping that calling
```
$entity_manager->persist($new_parent_entity);
$uow->computeChangeSet(
$entity_manager->getClassMetadata('ParentEntity'),
$new_parent_entity
);
```
would be enough to also persist the related entities and their relations, but apparently that doesn't work. The UoW seems to know about the new related entities (i. e. inside the "OtherChildEntities" collection), but the changesets of these entities are empty, so the flush operation always fails with a `PDOException` because no parameters were bound to the `PDOStatement`.
Did I do something wrong (the relations are all marked as "cascade=persist" so that shouldn't be it)? I've read in this thread https://github.com/doctrine/doctrine2/issues/5920 that you have to 'take ownership' of your changes and register them with the UoW yourself, so does that mean that I really have to manually compute the changesets of all related entities?
Contributor guide
Assessment
This issue has not been assessed yet.