本文介绍了Doctrine 2多级继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在多级继承方面遇到了一些麻烦

i have some trouble with multiple level inheritance

/**
 * @ORM\Entity
 * @ORM\Table(name="et_date")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"Relative" = "DateRelative", "Absolue" = "DateAbsolue"})
 */
class Date {}

/**
 * @ORM\Entity
 * @ORM\Table(name="et_date_absolue")
 */
class DateAbsolue extends Date{}

/**
 * @ORM\Entity
 * @ORM\Table(name="et_date_relative")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"Inscription" = "DateRelativeInscription", "Devoir" = "DateRelativeDevoir"})
 */
class DateRelative extends Date {}

/**
 * @ORM\Entity
 * @ORM\Table(name="et_date_relative_inscription")
 */
class DateRelativeInscription extends DateRelative{}

我的DateRelative实体的我的鉴别器列不存在...

My discriminator column of my DateRelative entity doesn't exists...

推荐答案

这是一个老问题,但我会回答以防万一这有助于其他人在路上...

This is an old question, but I'll answer just in case this helps someone else down the road...

您不能将鉴别器列命名为type,因为type是保留的SQL关键字。

You cannot name your discriminator column "type", because "type" is a reserved SQL keyword.

在尝试命名我的一个表Like时,我遇到了类似的问题,这也是一个保留的SQL关键字。

I had a similar issue when trying to name one of my tables "Like" which is also a reserved SQL keyword.

作为参考,这里是指向所有保留SQL关键字列表的链接。

As a reference, here is a link to a list of all reserved SQL keywords.

这篇关于Doctrine 2多级继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 04:11