3
votes

i use two classes:

namespace Test;
use Doctrine\ORM\Mapping as ORM;

/**
 *@Table()
 *@InheritanceType("Joined")
 *@DiscriminatorMap({"baseclass"="BaseClass", "subclass"="SubClass"}
 *@Entity
*/
class BaseClass{

     /**
      *@Column(name="id", type="integer")
      *@Id
      *@GeneratedValue(strategy="IDENTITY")
     */
     private $id;
}


namespace Test;
use Doctrine\ORM\Mapping as ORM;

/**
 *@Table()
 *@Entity
 */
class SubClass extends BaseClass{

     /**
      * @Column(name="v", type="string", nullable="false")
      */
      private $v;
}

I am not able to persist a SubClassObject. I receive the following errorMessage:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dtype' in 'field list'

I am new to Doctrine and ORM so I need some help here.

Edit: After using the cli orm:create-schema:tool the baseclass has a dtype-field. Is it possible to create the entity without that field and what does this field stand for?

1

1 Answers

6
votes

The dtype-field is the default @DiscriminatorColumn. You can change the column name as follows:

@InheritanceType("Joined")
@DiscriminatorColumn(name="[CHANGE]", type="string")
@DiscriminatorMap({"baseclass"="BaseClass", "subclass"="SubClass"}

In an inheritance hierarchy it is not possible to skip this field. This field maps the type to the appropriate class. In your example: Type subclass refers to the SubClass class.