DDC-2704: When using Discriminator EntityManager#merge fails #3446

doctrinebot opened this Issue Sep 25, 2013 · 5 comments

2 participants


Jira issue originally created by user vladykx:

I have the following hierarchy:

  • AgentConfig has relation ManyToOne with AgentTask.
  • AgentTask has DiscriminatorColumn & DiscriminatorMap assigned to it.
  • AgentTask has relation ManyToOne with AgentTaskConfig.

I believe the problem is because of the following:

UnitOfWork#doMerge has the tries to get properties the following way:

// Merge state of $entity into existing (managed) entity
foreach ($class->reflClass->getProperties() as $prop) {

This obviously doesn't get the parent class (AgentTask) properties.

Later on UnitOfWork fails on line:


because $prevManagedCopy doesn't have properties set from entity.

My proposal is to get the properties the following way:

$properties = $class->reflClass->getProperties();
$parent = $class->reflClass;
while (($parent = $parent->getParentClass()) != null) {
    $properties = array_merge($parent->getProperties(), $properties);

// Merge state of $entity into existing (managed) entity
foreach ($properties as $prop) {

Comment created by rkj:

I have this problem as well in .
The Merge operation does not copy properties of any parent class to the managed copy. My workaround when merging entities with inheritance is:
1. Receive detached entity that is instance of a subclass.
2. fetch a managed copy of the entity from database with id of detached entity.
3. manually set properties on the managed entity.
4. flush to save changes.

This is obviously only manageable with a relatively simple datastructure, and quickly becomes very messy with more complex entities and relationship hierarchies.

Would really appreciate a fix for this


Comment created by @ocramius:

A temporary workaround is to change properties into protected. I'll mark this for 2.5 and see if it can be fixed by then.


Comment created by @ocramius:

Handled in DDC-3524


Issue was closed with resolution "Fixed"

@Ocramius Ocramius was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.5 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment