DDC-3181: Class Table Inheritance - wrong table order on insert with more than one level of inheritance #3941

Open
opened 2026-01-22 14:32:02 +01:00 by admin · 1 comment
Owner

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

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](http://www.doctrine-project.org/jira/browse/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
admin added the Bug label 2026-01-22 14:32:02 +01:00
Author
Owner

@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

@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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3941