Search code examples
phpmysqlentity-frameworksymfonyextend

How to understand extended entities in Symfony2


I have a project where I would like to have three different kind of "customers".

  • BaseCustomer

    • firstName
    • lastName
    • email
    • phone
  • Customer extends BaseCustomer

    • streetName
    • streetNo
    • zipcode
    • city
  • Member extends Customer

    • memberNo

I know how to setup the single entities with orm/tables etc. But my knowledge fails when it comes to extending the entities.

What is the best practice about extending entities when I also need to implement mysql (inno) tables?


Solution

  • If you work with Doctrine its inheritance mapping is what you're looking for:

    http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html

    You can choose from MappedSuperclasses, Single or Class Table Inheritance. The different pro's and con's are listed and it's depending on your situation (and other entities which might be related to your customer objects).