问题描述
您如何(如果可能的话)使用 Doctrine2 更改实体类型,使用它的类表继承?
How (if possible at all) do you change the entity type with Doctrine2, using it's Class Table Inheritance?
假设我有一个 Person
父类类型和两个继承类型 Employe
和 Client
.我的系统允许创建一个人员并指定它的类型 - 这很容易实现 - 但我也希望能够将人员从员工更改为客户,同时维护 Person
-级别信息(即 id 和其他相关记录).
Let's say I have a Person
parent class type and two inherited types Employe
and Client
. My system allows to create a Person and specify it's type - that's fairly easy to implement - but I'd also like to be able to change the person from an Employe to a Client, while maintaining the Person
-level information (it's id and other associated records).
Doctrine2 有没有一种简单的方法可以做到这一点?
Is there a simple way to do this with Doctrine2?
推荐答案
我昨天也在寻找这种行为.
I was looking for this behaviour yesterday also.
最后,在与 freenode 上#doctrine 的人交谈后,我被告知这是不可能的.
In the end, after speaking with people in #doctrine on freenode, I was told that it is not possible.
如果你想这样做,那么你必须经历这个:
If you want to do this, then you have to go through this:
- 抓取 Person 实体.
- 更新鉴别器列,使其不再是人"并将其更改为员工"
- 在您的
Employee
表中为此继承创建相应的行.
- Grab the Person Entity.
- Update the discrimator column so that it is no longer a 'person' and change it to 'employee'
- Create a corresponding row inyour
Employee
table for this inheritance.
删除继承
同样,如果你想删除继承,你必须......
Removing Inheritance
Likewise if you want to remove inheritance, you have to..
- 抓取 Person 实体.
- 更新鉴别器列,使其不再是雇员"并将其更改为人".
- 删除
Employee
表中的相应行.(是的,您必须删除它,仅更改鉴别器参数是不够的).
- Grab the Person Entity.
- Update the discrimnator column so that it is no longer an 'employee' and change it to a 'person'.
- Delete the corresponding row in your
Employee
table. (Yes you have to delete it, just change the discrimator coumn is not sufficient).
这可能晚了 7 个月,但对于任何其他希望支持此类功能的事物来说,这至少是正确的答案.
This might be 7 months late, but it is at least the correct answer for anything else looking to suport such a feature.
这篇关于如何在 Doctrine2 CTI 继承中更改和实体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!