根据Doctrine

时间:2016-03-09 15:23:38

标签: database symfony doctrine-orm doctrine

我有一个名为Question的抽象类。 现在,我有很多类型的问题,例如OneToChooseFrom或ManyToChooseFrom,它们扩展了Question类。

我想要做的是将所有这些类型的问题存储在单个'问题中。表,当我检索它们时,我希望它们根据question_type列正确映射到OneToChooeFrom类或ManyToChooseFrom类。

我知道我可以使用单表继承,但我已经在使用类表继承。所以我不能同时使用它们。

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({
 *      "description" = "Acme\SurveyBundle\Entity\Description",
 *      "question" = "Acme\SurveyBundle\Entity\Question"
 *     })
 * @ORM\Table(name="survey_item")
 */
abstract class Item
{
}

/**
 * @ORM\Entity()
 * @ORM\Table(name="survey_question")
 */
abstract class Question extends Item
{
    /**
     * @ORM\Column(name="question_type", type="string")
     *
     * @var string
     */
     protected $questionType;
}

final class OneToChooseFrom extends Question
{
    protected $questionType = 'oneToChooseFrom';
}

final class ManyToChooseFrom extends Question
{
    protected $questionType = 'manyToChooseFrom';
}

0 个答案:

没有答案