简体   繁体   English

教义类表继承-多种类型

[英]Doctrine Class Table Inheritance - Multiple Types

I'm trying to make a Listing system for a classifieds-like site in Symfony. 我正在尝试为Symfony中的类似分类广告的站点创建清单系统。 I want to have multiple Listing types with different fields (and some common fields). 我想要具有多个具有不同字段(和一些常见字段)的列表类型。

I was going to make a main Listing class which would have all of the common fields (name, description, price) and then subclasses with the fields specific to the different types. 我要制作一个主要的Listing类,该类将具有所有公共字段(名称,描述,价格),然后将其子类具有特定于不同类型的字段。

Through my research, it sounds like Class Table Inheritance in Doctrine is the best solution. 通过我的研究,听起来像“ Doctrine中的类表继承”是最好的解决方案。 Am I correct in this? 我对此是否正确? I may have up to 10 "subtypes" and heard it may not be great for performance. 我可能有多达10个“子类型”,听说它可能对性能不好。

    /**
    * Listing
    *
    * @ORM\Table(name="listing")
    * @ORM\InheritanceType("JOINED")
    * @ORM\DiscriminatorColumn(name="discr", type="string")
    * @ORM\DiscriminatorMap({"listing" = "Listing","recreation-vehicle" = "RecreationVehicle","vehicle" = "Vehicle","event" = "Event","classified" = "Classified","buyandsell" = "BuySell","real-estate" = "RealEstate","business" = "Business"})
    */
    class Listing
    {

}

Thanks! 谢谢!

In the doctrine documentation of Class Table Inheritance you can find some considerations using it. 类表继承的理论文档中,您可以找到使用它的一些注意事项。 Some important facts excerpted: 摘录了一些重要的事实:

  • provides the greatest flexibility at design time, since changes to any type are always limited to that type's dedicated table 在设计时提供最大的灵活性,因为对任何类型的更改始终限于该类型的专用表
  • This strategy inherently requires multiple JOIN operations to perform just about any query which can have a negative impact on performance, especially with large tables and/or large hierarchies 该策略固有地需要多个JOIN操作来执行几乎任何可能对性能产生负面影响的查询,尤其是对于大型表和/或大型层次结构

As you have only one inheritance level (all listings extends your base Listing ) it should not a big impact. 由于您只有一个继承级别(所有清单都扩展了基本Listing ),因此影响不大。

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

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