[英]Doctrine 1.2 class table inheritance workaround?
ok, first of all, I know this is not possible with 1.2., that is why I'm looking for a workaround. 好的,首先,我知道1.2。这是不可能的,这就是为什么我正在寻找一种解决方法。
And no, unfortunately I can't use Doctrine 2, because my shared hosting server is stuck at PHP 5.2.16, and the admin refuses to install PHP 5.3 support. 不,不幸的是我不能使用Doctrine 2,因为我的共享托管服务器停留在PHP 5.2.16,并且管理员拒绝安装PHP 5.3支持。
So, here is my problem, basic parent-child issue: 所以,这是我的问题,基本的亲子问题:
Lets say I have a base class User
and child classes Customer
, Seller
, Admin
. 假设我有一个基类
User
和子类Customer
, Seller
, Admin
。
I have been looking at the inheritance methods: simple (pretty useless IMO), concrete and column aggregation , and even a workaround for " fake class table inheritance " found here . 我一直在研究继承方法: 简单 (相当无用的IMO), 具体和列聚合 ,甚至是在这里找到的“ 假类表继承 ”的解决方法。
What I really need is " class table inheritance ", in other words User
maps to separate table, which contains all shared values, and child tables define map to separate tables defining only their specific columns. 我真正需要的是“ 类表继承 ”,换句话说,
User
映射到包含所有共享值的单独表,子表定义映射到仅定义其特定列的单独表。
I have given up on perfection :) in PHP<5.3, I really don't care how will it be stored in the db, but my object model NEEDS to have all functionality. 我放弃了完美 :)在PHP <5.3中,我真的不在乎它将如何存储在数据库中,但我的对象模型需要具备所有功能。
So what is the best choice for a workaround? 那么解决方法的最佳选择是什么?
This is what I need. 这就是我需要的。
workingHours
defined, which is a Seller specific value) workingHours
,这是卖方特定的值) Querying the base table would also be nice, but as I can see this is one of the biggest problems, it is not a must have. 查询基表也很不错,但正如我所看到的,这是最大的问题之一,它不是必须的。
I hope you understand my question. 我希望你理解我的问题。 Any advice would be appreciated, because I really don't know what to do here.
任何建议都会受到赞赏,因为我真的不知道该怎么做。
I had the very same problem a few days ago, and I chose inherinance by column aggregation. 几天前我遇到了同样的问题,我通过列聚合选择了继承。 The underlying concept is not the cleanest or most beautiful solution ever invented, but does the trick, and meets all your requirements, except one:
潜在的概念并不是有史以来最干净或最美丽的解决方案,而是诀窍,并满足您的所有要求,除了一个:
The one thing that fails here is that I emphasized with a bold font, but you can easily work it around. 这里失败的一件事是我用粗体字强调,但你可以很容易地解决它。 You can override the setters and getters in your child classes, like that if anyone tries to access or modify a field on a Seller object that belongs to the Customer, then you do not allow it (throw an exception, return false, etc...).
您可以覆盖子类中的setter和getter,如果有人试图访问或修改属于Customer的Seller对象上的字段,那么您不允许它(抛出异常,返回false等等)。 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.