繁体   English   中英

空继承的实体Symfony2

[英]empty inherited entity Symfony2

我有这个架构的例子

abstract class Class1

    attr1
    attr2

class Class2 extends Class1

    /**
    * @ORM\OneToMany("Class3")
    */
    attr3Array

class Class3

    /**
    * @ORM\ManyToOne(targetEntity="Class2")
    */
    attr3

这只是一个伪代码来呈现我的问题。 当我尝试生成我的数据库时,我有这个错误

[Doctrine\ORM\Mapping\MappingException]
Entity 'Class2' has to be part of the discriminator map of 'Class1' to be properly mapped   
  in the inheritance hierarchy. Alternatively you can make 'Class2' an abstract class to avoid this exception from occurring.  

但我想创建Class2的实例,我不想要一个抽象的Class2是否有其他方法来模拟我的实体?

尝试将父类定义为映射的超类。 如果有@ORM\\Entity注释,则需要删除它。

/**
 * @ORM\MappedSuperclass
 */
abstract class Class1
{
}

如果Doctrine不喜欢MappedSuperclasses是抽象的,那么你可能还必须使这个类成为非抽象类。

有关继承映射的更多信息可以在文档中找到 您也可以根据需要找到更合适的解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM