3
votes

I have a question about Doctrine's Mapping Strategies.

There are two different ways to achieve inheritance: MappedSuperclass or Inheritance Mapping. What I am trying to do is the following:

/** 
 * @ORM\Entity
 * @ORM\InheritanceType("SINGLE_TABLE")  
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"B" = "B","C" = "C"})
 * @ORM\HasLifecycleCallbacks
 */
abstract class A {
    OneToManyMappingToD
}

/** 
 * @ORM\Entity
 */
class B {
}

/** 
 * @ORM\Entity
 */
class C {
}

/** 
 * @ORM\Entity
 * @ORM\InheritanceType("SINGLE_TABLE")  
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"E" = "E","F" = "F"})
 * @ORM\HasLifecycleCallbacks
 */
abstract class D {
    ManyToOneToA
}

/** 
 * @ORM\Entity
 */
class E {
}

/** 
 * @ORM\Entity
 */
class F {
}

The Mapping validation doesn't note any problems, Mapping files are ok. But when I use these entities in a form -> submit() I have to wait about more than 30 seconds and Doctrine executes more than 8 000 calls. So what I think is that something is wrong with my mapping.

I can't use any MappedSuperClasses, because I definitely need the oneToMany Relations. I think the problem is, that class A and D are not part of the discriminatorMap and that doctrine can't map the relations correctly. But A and D are not ment to be a regular entity, because they just provide basic attributes.

How can I achieve this without getting more than 8 000 SELECT calls of doctrine?

Thanks!

1

1 Answers

1
votes

From my experience, using Class Table Inheritance works well for this type of association.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#class-table-inheritance

The documentation states that there are performance impacts of using this strategy, but I can't believe it would generate 8000 SELECT queries.