主义:扩展实体类 [英] Doctrine: extending entity class
问题描述
我想扩展Entity\Base类,在Doctrine 2.1中怎么做?我的研究表明,每当有人遇到这样的问题,他会切换到Doctrine 1.2:)n我使用yaml配置
教义2.X实体作为POPO(普通老PHP对象)。
为了实现正确扩展,Doctrine强制您使用名为Mapped Super Classes的JPA的概念。
这个想法很简单。每当你想有一个基类,并希望你的实体从它扩展(我不是在DB级别继承),所有你需要做的是创建你的Base类作为MappedSuperClass。
I would like to extend Entity\Base classes, how to do this in Doctrine 2.1? My research showed that whenever someone encounters the problem with doing this he switches to Doctrine 1.2 :)n I am using yaml configuration
Doctrine 2.X Entities work as POPOs (Plain Old PHP Objects). To achieve extending correctly, Doctrine enforces you to use a concept from JPA called Mapped Super Classes. The idea is pretty simple. Whenever you want to have a base class and want your entities to extend from it (I'm not talking about inheritance at DB level), all you need to do is create your Base class as a MappedSuperClass.
Here is an example: http://www.doctrine-project.org/docs/orm/2.1/en/reference/inheritance-mapping.html#mapped-superclasses
Thanks
这篇关于主义:扩展实体类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!