DDC-1391: new class mapped by self but cannot flush #1739

Closed
opened 2026-01-22 13:23:53 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 23, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user icefish:

We create an entity class ,but it has an column mapped by this class
ex:
$user= new User();
$user->setParent($user);

but can not to flush;

Have any method to Solve it?

Originally created by @doctrinebot on GitHub (Sep 23, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user icefish: We create an entity class ,but it has an column mapped by this class ex: $user= new User(); $user->setParent($user); but can not to flush; Have any method to Solve it?
admin added the Bug label 2026-01-22 13:23:53 +01:00
admin closed this issue 2026-01-22 13:23:54 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 25, 2011):

Comment created by @beberlei:

Its not a bug, this dependency graph cannot be solved during flush. You have to do two transactions.

$user = new User;
$em->persist($user);
$em->flush();

$user->setUser($user);
$em->flush();

This is not a limitation of Doctrine, if you have a table "foo [id, parent_id]" and try to insert a new row that points to itself then this would only be possible with 3 sql statements, INSERT .., SELECT LAST_INSERT_ID(), UPDATE ...

@doctrinebot commented on GitHub (Sep 25, 2011): Comment created by @beberlei: Its not a bug, this dependency graph cannot be solved during flush. You have to do two transactions. ``` $user = new User; $em->persist($user); $em->flush(); $user->setUser($user); $em->flush(); ``` This is not a limitation of Doctrine, if you have a table "foo [id, parent_id]" and try to insert a new row that points to itself then this would only be possible with 3 sql statements, INSERT .., SELECT LAST_INSERT_ID(), UPDATE ...
Author
Owner

@doctrinebot commented on GitHub (Sep 25, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Sep 25, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1739