[DMIG-42] Invalid foreign key created for relationships using single table inheritance. Created: 03/Jun/13 Updated: 03/Jun/13
|Reporter:||Chris Collins||Assignee:||Benjamin Eberlei|
This issue arises when associating an object that uses SINGLE_TABLE inheritance with another object. When the schema is updated, or migrations are created (I'm doing this via Symfony 2's doctrine:schema:update and doctrine:migrations:diff commands), a foreign key is added to the table that is valid for only one of the child classes.
A quick example: The aim here is to have a "user" type that can be associated to many "books" and "videos" (and other types not shown here) via a single table named "user_content" that contains a discriminator column and the ID of a video/book/other item of content.
When migrating/updating schema for this, you should see something like the following:
The first constraint is fine as "user_id" should always point at a row in the "user" table, but the second constraint is invalid: "content_item_id" will not always refer to an entry in the "video" table, it will sometimes refer to an entry in the "book" table, potentially throwing errors on inserts etc.
If I've done something incorrectly, misunderstood how this this type of inheritance should work or if you need further details, please let me know.