Is it possible (and recommended) to use multiple models for one table?
I have multiple types of “people” (teacher, students, employees, firms) and would like to store them in the same table. They have all personal data in common, but have other relations (for ex. students -> firms, teacher -> rooms and more), additional information (for ex. firms: firm name, teachers: education) and more.
It would be nice to get some best practices for such cases.
It’s really simple! You have to make entities like this:
And in Teacher.php file:
The key to success are those two annotation:
First is telling ORM what column will be used to verify if person is Teacher or not.
Second is telling what classes are extending base Person class and what to put in column i mentioned before. When you do that you will have two tables, but in Teacher you will have only data you add to Teacher entity 🙂
Generally speaking when using ORM you have to think on the object abstraction level and don’t care about DB (well, that’s not entirely true, but it’s general idea) 🙂