[英]One entity to many entities symfony
With doctrine on symfony, looking to an entity linked to multiple entities on a single remaining column.根据 symfony 的原则,在一个剩余的列上寻找链接到多个实体的实体。 For example :例如 :
Entity engine extend two entities实体引擎扩展两个实体
I want to use a single column in engine, because I'm having a very large number of linked table.我想在引擎中使用单列,因为我有大量的链接表。
I can not find what is the best practice in this kind of scheme.我找不到这种方案的最佳实践是什么。 This is possible?这个有可能? how ?如何 ?
thanks in advance提前致谢
You can do this with ' Class Table Inheritance '.您可以使用“ 类表继承”来做到这一点。 Your code will look like this:您的代码将如下所示:
namespace MyProject\Model;
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"car" = "Car", "plane" = "Plane"})
*/
class Vehicle
{
// ...
}
/** @Entity */
class Plane extends Vehicle
{
// ...
}
/** @Entity */
class Car extends Vehicle
{
// ...
}
This solves your problem of having only one foreign key on your Engine table.这解决了您的 Engine 表上只有一个外键的问题。 It also helps you have a more clear code when you have other 'shared' properties (for example a date of manufacture)当您有其他“共享”属性(例如制造日期)时,它还可以帮助您获得更清晰的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.