I have need to create this database scheme in Symfony Entities :
ClassA:
- id
- name
- ... some other attributes only for class A
ClassB:
- id
- name
- ... some other attributes only for class B
ClassC:
- id
- name
- ... some other attributes only for class C
Course:
- id
- name
- type
- class_id
- class_type [A, B, C]
- ...
I need to create relations between Course Entity (using the class_id) with the other entities (ClassA, ClassB, ClassC) (using the id) and using the class_type (A, B, C).
A Course is not a class and a class is not a course. There is no inheritance here. In my project I'm using this concept (id and type to map different entities). So I need to solve this problem with a simple example like this one
I thought about using @ORM\DiscriminationMap here:
/**
* Course
*
* @ORM\Table(name="Course")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="course_type", type="string")
* @ORM\DiscriminatorMap({"A" = "ClassA", "B" = "ClassB", "C" = "ClassC"})
*/
abstract class Course
{
//...
}
class ClassA extends Course
{
//...
}
class ClassB extends Course
{
//...
}
class ClassC extends Course
{
//...
}
Or something like this.
But I don't want to copy the Course's attributes in the ClassA, ClassB, ClassC entities because "extends" will copy the parent entity's attributes to the child.
It's not about inheritence. I need to keep the database scheme described above without adding any additional attributes from the other entities.
Thank you
Class(A|B|C)andCourse? is it two different database tables right? - Petro Popelyshko