Skip to content

Do I have to manually compute the changeset of new related entities in onFlush? #6281

Open
@floriandammeyer

Description

@floriandammeyer

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 #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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions