PHP – Doctrine 2 and Concrete Table Inheritance

doctrineinheritanceormPHP

I use Doctrine 2 and I've read some articles on inheritance strategies' mapping with ORM.
I've seen three main strategies : "Class table inheritance", "Concrete table inheritance" and "Single table inheritance".

With Doctrine 2, I managed an install of "Class Table Inheritance" (CTI) and "Single Table Inheritance" (STI).

In some cases, I think use the "Concrete Table Inheritance" is most appropriate, but i didn't find any documentation which show this strategy in Doctrine 2.

Why there is no "Concrete Table Inheritance" with Doctrine 2 ?

Is it for performance ? What is the reason ?

Best Answer

Concrete table inheritance is a problematic inheritance form as it requires the ORM to update multiple tables if a field in a supertype changes. The upside is that it doesn't require joins with supertype tables in many cases but it comes, as said, with the downside that it denormalizes your model. Not many ORMs support it (Hibernate/NHibernate does, but warns against it).

It's solely an optimization option, there's no logical 'need' for it as in 'it fits my application better', as the only difference with other inheritance forms is that it is stored differently in the DB.

If possible, stay away from inheritance mappings in ORMs btw. Only use it if there is clear entity inheritance in your domain. Don't use it for mapping pure OO structural aspects to the DB, e.g. avoid things like a supertype which has only fields like 'CreatedBy' and 'UpdatedOn' and is then inherited by all entities.