databasedoctrine-ormclass-table-inheritance

How to change and entity type in Doctrine2 CTI Inheritance


How (if possible at all) do you change the entity type with Doctrine2, using it's Class Table Inheritance?

Let's say I have a Person parent class type and two inherited types Employe and Client. My system allows to create a Person and specify it's type - that's fairly easy to implement - but I'd also like to be able to change the person from an Employe to a Client, while maintaining the Person-level information (it's id and other associated records).

Is there a simple way to do this with Doctrine2?


Solution

  • I was looking for this behaviour yesterday also.

    In the end, after speaking with people in #doctrine on freenode, I was told that it is not possible.

    If you want to do this, then you have to go through this:

    Upgrading a User

    1. Grab the Person Entity.
    2. Update the discrimator column so that it is no longer a 'person' and change it to 'employee'
    3. Create a corresponding row inyour Employee table for this inheritance.

    Removing Inheritance

    Likewise if you want to remove inheritance, you have to..

    1. Grab the Person Entity.
    2. Update the discrimnator column so that it is no longer an 'employee' and change it to a 'person'.
    3. Delete the corresponding row in your Employee table. (Yes you have to delete it, just change the discrimator coumn is not sufficient).

    This might be 7 months late, but it is at least the correct answer for anything else looking to suport such a feature.