mirror of
https://github.com/doctrine/orm.git
synced 2026-04-26 16:08:03 +02:00
DDC-3181: Class Table Inheritance - wrong table order on insert with more than one level of inheritance #3941
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jun 20, 2014).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user sx9:
note: this issue seems the same as DDC-732
When using class table inheritance with multiple levels i.e.:
Object -> SolidObject -> Building -> House
(House inherits from Building, Building from SolidObject, SolidObject from Object)
Object has the discriminator column and mapping. When persisting a new House entity I get a foreign key error because there is no row in the Building table.
I searched in the Code and found the problem. In the class "Doctrine\ORM\Persisters\JoinedSubclassPersister" in function "executeInserts()" around line 146 the array $subTableStmts is first declared and then filled with insert statements. The statement of the House-table is first added, and then the parent-tables (except the root-table "Object", since that one is executed first).
So the order in which the insert statements are executed is:
1 Insert into Object ...
2 Insert into House ... (which causes the error)
3 insert into Building ...
4 Insert into SolidObject
I edited the source to insert into the parent-tables (first SolidObject, then Building) before inserting into the table that belongs to the class that is persisted (House). And this works
@doctrinebot commented on GitHub (Nov 26, 2014):
Comment created by bmohammed:
hello, can you please send me the modified lines or just share with me the whole method executeInserts.
thanks in advance