Issue
With doctrine on symfony, looking to an entity linked to multiple entities on a single remaining column. For example :
Entity engine extend two entities
- Entity plane
- Entity car
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
Solution
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. It also helps you have a more clear code when you have other 'shared' properties (for example a date of manufacture)
Answered By - Stephan Vierkant
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.