![](/img/trans.png)
[英]Symfony2 / Doctrine mapped superclass in the middle of class table inheritance
[英]Symfony2 abstract class multiple inheritance with Doctrine
基本上,它是分类系统的开始,其中一些是可嵌套的,有些则不是。 我开始尝试制作2层抽象类(Taxonomy和OfferCategory),因为它们都不能用作最终实体。 我使用了MappedSuperClass,但是我收到了以下错误:
[Doctrine\ORM\ORMException]
Column name `id` referenced for relation from LCH\CatalogBundle\Entity\HomeOfferCategory towards LCH\CatalogBund le\Entity\OfferCategory does not exist.
我的主要关键字段是id ...
从更一般的角度来看,Doctrine提供的计划的最佳实现是什么?
谢谢 !
编辑:我试图直接在我的RootOfferCategory类中转置所有OfferCategory成员。 通过改变双方的targetENtity,不再有错误。 意思是你不能自己引用映射的超类?
分类 :
/**
* Class Taxonomy
* @package LCH\CatalogBundle\Entity
* @ORM\MappedSuperclass
*/
abstract class Taxonomy implements TaxonomyInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string the category name
* @ORM\Column(name="name", type="string", length=255)
*/
protected $name;
}
** OfferCategory:**
/**
* OfferCategory
* @ORM\MappedSuperclass
*/
abstract class OfferCategory extends Taxonomy
{
/**
* @var OfferCategory the category parent
* @ORM\ManyToOne(targetEntity="LCH\CatalogBundle\Entity\OfferCategory",inversedBy="children", cascade={"persist"})
* @ORM\JoinColumn(name="parent_id", referenceColumnName="id")
*/
protected $parent;
/**
* @var OfferCategory the children categories
* @ORM\OneToMany(targetEntity="LCH\CatalogBundle\Entity\OfferCategory",mappedBy="parent", cascade={"persist"})
*/
protected $children;
}
RootOfferCategory
/**
* RootOfferCategory
* Represents one root top category
* @ORM\Table()
* @ORM\Entity(repositoryClass="LCH\CatalogBundle\Entity\RootOfferCategoryRepository")
*/
class RootOfferCategory extends OfferCategory
{
}
对不起,战后到了。
从Doctrine文档的这一部分 :
映射的超类不能是实体,它不是可查询的,并且由映射的超类定义的持久关系必须是单向的(仅具有拥有方)。
这意味着根本不可能在映射的超类上进行一对多关联。
此外,只有当映射的超类仅在一个实体中使用时,才能实现多对多关联。此时此情况。为了进一步支持继承,必须使用单个或连接表继承功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.