0

I got a question. I have been waiting on the DiscriminatorColumn annotation in Doctrine 2 but now that I got it via Update of Doctrine I am not able to find the Hibernate's DiscriminatorValue annotation equivalent in Doctrine. FYI, my Doctrine version is "doctrine/orm": "^2.5.6" and "doctrine/doctrine-bundle": "~1.6" but I cannot find such annotation.

My basic desire here is to set the Discriminator Column value per child class not in the main class in the DiscriminatorMap.

  • I solved this for myself a while back. Have a read: https://stackoverflow.com/questions/45015356/zf2-doctrine-2-child-level-discriminators-with-class-table-inheritance. Not quite sure what you mean with "hibernate" though?... – rkeet Aug 10 '17 at 10:22
  • Well, I mean the Java Hibernate ORM - http://hibernate.org/ :) – Momchil Milev Aug 11 '17 at 11:22

1 Answers1

0

Like my comment stated, I had this issue a while back as well, where I wanted to "declare" new DiscriminatorMap entries on the child-classes. The short answer is: do not declare a map at all. Doctrine takes care of it.

Have a read of my full answer. This works for me using Class Table Inheritance (CTI), the docs state that it should work the same for Single Table Inheritance (STI).

The basic code setup to let Doctrine handle it for you is:

<?php
namespace My\Namespace\Entity;

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * // NOTE: No DiscriminatorMap!!!
 */
class Person
{
    // ...
}


<?php
namespace My\Other\Namespace\Entity;

/** @Entity */
class Employee extends \My\Namespace\Entity\Person
{
    // ...
}
rkeet
  • 3,406
  • 2
  • 23
  • 49