请在symfony2 php中从抽象类扩展的Doctrine Entity中使用dicriminator map

时间:2012-07-13 01:25:17

标签: php symfony doctrine-orm

我有这个结构

`UserInterface.php`
 abstract class User implements UserInterfacee in model`
`class student extends user.php`
`class teacher extends user.php`

现在我应该在哪个课程中使用这个学说代码

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"user" = "User", "student" = "Student"})
 */

1 个答案:

答案 0 :(得分:2)

您应该在父类中使用继承注释。

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"student" = "Student", "teacher" = "Teacher"})
 */
  class User
 {
 // ...
 }

  /** @Entity */
  class Student extends User
   {
    // ...
  }

  /** @Entity */
  class Teacher extends User
   {
    // ...
  }