简体   繁体   English

如何在捆绑包中扩展 symfony 实体

[英]How to extend symfony entity in bundle

Is there a way I can extend a symfony entity in another bundle using @DiscriminatorMap without having to specify it beforehand?有没有一种方法可以使用@DiscriminatorMap在另一个包中扩展 symfony 实体,而无需事先指定它?

BundleA捆绑A

BundleB捆绑B

  • How can I add a new Event (ie UpdateEvent ) to the Event -hierarchy without modifing BundleA ?如何在不修改BundleA的情况下将新事件(即UpdateEvent )添加到Event层次结构?

You can try letting doctrine auto-generate the discriminator map.您可以尝试让 doctrine 自动生成鉴别器 map。
From the last bullet point in this section of the docs :文档本节的最后一个要点:

If no discriminator map is provided, then the map is generated automatically.如果没有提供判别器 map,则自动生成 map。 The automatically generated discriminator map contains the lowercase short name of each class as key.自动生成的鉴别器 map 包含每个 class 的小写短名称作为键。 So you would:所以你会:

  1. Omit the @DiscriminatorMap declaration in BundleA.省略 BundleA 中的@DiscriminatorMap声明。
  2. Extend the entity as normal in BundleB (making sure the short name of each class is unique).在 BundleB 中正常扩展实体(确保每个 class 的短名称是唯一的)。
  3. Update the database schema.更新数据库架构。

EDIT编辑
As pointed out by ju_ in the comments, this solution will apparently not work with Doctrine ORM 3.0, but should still be valid for versions 2.5 - 2.7正如 ju_ 在评论中指出的那样,此解决方案显然不适用于 Doctrine ORM 3.0,但仍应适用于2.5 - 2.7版本

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

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