1

With Doctrine ORM 2.4 I want to implement something that looks like this example:

Person {
    private $name;
    private $email;
}

Student extends Person {
    private $favoriteTeacher;
}

Teacher extends Person {
    private $subjectsTaught;
}

But, I want ONE Person to be able to be a Student and a Teacher at the same time, like a natural person being a student in one situation and a teacher in another.

On the database level that would mean that we have the person's data only ONCE in the system and NOT having to change the email twice when the person's email changes.

The representation on a database level could be something like this:

person: 
- id (primary key)
- name 
- email

student:
- person_id (primary & foreign key)
- favoriteTeacher

teacher: 
- person_id (primary & foreign key)
- subjectsTaught

So the following example data would make total sense:

person: id=1, name=peter, ...
student: person_id=1, ...
teacher: person_id=1, ...

Is there a Doctrine construct that does that? As far as I understood all the alternatives presented here in the doctrine docs are creating two entries for Person, when you have someone being a teacher and a student.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
stefax
  • 11
  • 3
  • This isn't a Doctrine limitation but a limitation in OOP in PHP. You cannot extend multiple classes. – Gerry Oct 01 '13 at 13:59
  • Maybe this can help you: http://stackoverflow.com/questions/5938418/how-to-change-and-entity-type-in-doctrine2-cti-inheritance/18613748#18613748 – M. Foti Oct 01 '13 at 14:19
  • @Gerry: I don't want multiple class inheritance. I want several classes to extend from the same super class. I added the representation on a database level to the question to make it clearer. – stefax Oct 01 '13 at 18:23

0 Answers0