I was recently reading the Doctrine 2‘s best practices and was stopped by this:
25.3. Avoid composite keys
Even though Doctrine fully supports composite keys it is best not to use them if possible. Composite keys
require additional work by Doctrine and thus have a higher probability
of errors.
What I don’t get is this: if "Doctrine fully supports composite keys", how can it make mistakes when dealing with such keys?
Therefore I would like to ask this question as a community wiki, hoping it will help us understand what the "probability of errors" are:
Do you have examples to share showing situations you’ve ran into whereby Doctrine 2 was not handling composite keys well/as it should?
For my part I believe I’ve already ran into some issues with a very basic database schema containing a table which primary key is composed of 2 foreign keys:
When I generate my models, the entity corresponding to the
product_i18nentity isn’t created:Yet, I believe my database schema was properly created:
Also,
Doctrine 2‘sSchema Managershows that Doctrine seems to understand that relation perfectly (var_dumpoutput altered to make it more concise: removing things such asarray,RECURSION,string…):Therefore I’m in a situation whereby I can query the schema for the
product_i18ntable, but can’t interact with that table because the corresponding entity model wasn’t generated.UPDATE: as
user1136666pointed out: the known issues and limitations page odes state the following:The workaround is to define a surrogate key and add a unique constraint on the foreign keys, like so:
Feature request: http://www.doctrine-project.org/jira/browse/DDC-1926