主义:扩展实体类 [英] Doctrine: extending entity class

查看:103
本文介绍了主义:扩展实体类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想扩展Entity\Base类,在Doctrine 2.1中怎么做?我的研究表明,每当有人遇到这样的问题,他会切换到Doctrine 1.2:)n我使用yaml配置

解决方案

教义2.X实体作为POPO(普通老PHP对象)。
为了实现正确扩展,Doctrine强制您使用名为Mapped Super Classes的JPA的概念。
这个想法很简单。每当你想有一个基类,并希望你的实体从它扩展(我不是在DB级别继承),所有你需要做的是创建你的Base类作为MappedSuperClass。



这是一个例子: http://www.doctrine-project.org/docs/orm/2.1/en/reference/inheritance-mapping.html#mapped-superclasses




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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆