具有Doctrine2的联接表中的判别器 [英] Discriminator in a Joined Table with Doctrine2

查看:55
本文介绍了具有Doctrine2的联接表中的判别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Divers的抽象父类,该父类又由其他几个类扩展.因此,我使用单表继承策略将继承映射与D2一起使用.

I have an abstract parent class called Divers which is extended by few other classes.
So, I use inheritance mapping with D2 using Single Table Inheritance strategy.

namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * ParentClass
 * 
 * @ORM\Table(name="PARENTCLASS")
 * @ORM\Entity
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="idtable", type="string")
 * @ORM\DiscriminatorMap({
 *      "CHILD-CLASS1" = "ChildClassOne",
 *      "CHILD-CLASS2" = "ChildClassTwo",
 *      "CHILD-CLASS3" = "ChildClassThree",
 *      "CHILD-CLASS4" = "ChildClassFour"
 * })
 */
abstract class ParentClass
{
    ...
}

我要实现的是在浏览器中显示鉴别符,并带有一些简短说明,向用户解释鉴别符.
我用谷歌搜索了一个解决方案,例如将鉴别符放在连接表中,但一无所获.

What I want to achieve is to display the discriminator in the browser with a little description that explains what is it to the user.
I googled for a solution like putting the discriminator in a joined table but found nothing.

您对实现我的目标有何建议?

Do you have any advice to achieve my goal ?

在此先感谢您的帮助.

推荐答案

discriminator列对于Doctrine 2具有特殊含义,因此不能成为关系的一部分.

The discriminator column has special meaning for Doctrine 2 and thus cannot be part of a relation.

但是可以轻松解决.只需添加另一列,并为其赋予与鉴别符列相同的值即可.该值永远不会改变,因此很容易做到.然后,您当然可以像其他任何列一样使用新列.

But there is an easy work around. Just add another column and give it the same value that your discriminator column has. The value will never change so it's easy enough to do. You can then of course use your new column in the same way as any other column.

从数据库的角度来看,我知道有两个具有相同值的列并不理想.但是从对象的角度来看,这没什么大不了的,因为discriminator列从不公开为属性.这只是教义的运作方式.它希望该列全部显示.

I know having two columns with the same value is not ideal from a database perspective. But from an object perspective, it's no big deal since the discriminator column is never exposed as a property. And it's just the way doctrine works. It wants that column all to itself.

这篇关于具有Doctrine2的联接表中的判别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆