DDC-1461: Possible Regression with OneToOne relation #1834

Closed
opened 2026-01-22 13:27:35 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 31, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user johannes:

I have the following relations:


namespace Model;

use Doctrine\ORM\Mapping as ORM;

/****
 * @ORM\Entity(repositoryClass="Model\Repository\UserRepository")
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 * @ORM\HasLifecycleCallbacks
 * @ORM\Table(name="users")
 */
class User
{
    /****
     * @ORM\OneToOne(targetEntity="Model\TwitterAccount", orphanRemoval=true, fetch="EAGER", cascade = {"persist"}, inversedBy="user")
     * @var TwitterAccount
     */
    private $twitterAccount;
}

/****
 * @ORM\Entity(repositoryClass = "Model\Repository\TwitterAccountRepository")
 * @ORM\Table(name = "twitter_accounts")
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class TwitterAccount
{
    /****
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;

    /****
     * @ORM\OneToOne(targetEntity="Model\User", fetch="EAGER")
     */
    private $user;
}

now when I add a new account, the user-side is not updated with the id of the account, but the account is still saved to the database.

$twitterAccount = new TwitterAccount();
$user->setTwitterAccount($twitterAccount);
$em->persist($user);
$em->flush();

The twitterAccount_id of the users table is empty, but the new account is added to the "twitter_accounts" table with the correct user_id.

Originally created by @doctrinebot on GitHub (Oct 31, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user johannes: I have the following relations: ``` namespace Model; use Doctrine\ORM\Mapping as ORM; /**** * @ORM\Entity(repositoryClass="Model\Repository\UserRepository") * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") * @ORM\HasLifecycleCallbacks * @ORM\Table(name="users") */ class User { /**** * @ORM\OneToOne(targetEntity="Model\TwitterAccount", orphanRemoval=true, fetch="EAGER", cascade = {"persist"}, inversedBy="user") * @var TwitterAccount */ private $twitterAccount; } /**** * @ORM\Entity(repositoryClass = "Model\Repository\TwitterAccountRepository") * @ORM\Table(name = "twitter_accounts") * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") */ class TwitterAccount { /**** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ private $id; /**** * @ORM\OneToOne(targetEntity="Model\User", fetch="EAGER") */ private $user; } ``` now when I add a new account, the user-side is not updated with the id of the account, but the account is still saved to the database. ``` $twitterAccount = new TwitterAccount(); $user->setTwitterAccount($twitterAccount); $em->persist($user); $em->flush(); ``` The twitterAccount_id of the users table is empty, but the new account is added to the "twitter_accounts" table with the correct user_id.
admin added the Bug label 2026-01-22 13:27:35 +01:00
admin closed this issue 2026-01-22 13:27:36 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 31, 2011):

Comment created by @beberlei:

Do you know when this started to happen ?

@doctrinebot commented on GitHub (Oct 31, 2011): Comment created by @beberlei: Do you know when this started to happen ?
Author
Owner

@doctrinebot commented on GitHub (Oct 31, 2011):

Comment created by johannes:

I have reverted some commits of the ORM, but it doesn't seem to have happened recently, or it is a combination of different changes in one of the repositories.

What's weird is that the error does not occur when the user is new, but only if it already exists. It seems like somehow the UOW does not detect that it has changed.

@doctrinebot commented on GitHub (Oct 31, 2011): Comment created by johannes: I have reverted some commits of the ORM, but it doesn't seem to have happened recently, or it is a combination of different changes in one of the repositories. What's weird is that the error does not occur when the user is new, but only if it already exists. It seems like somehow the UOW does not detect that it has changed.
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2011):

Comment created by @beberlei:

This is deferred explicit related it seems.

@doctrinebot commented on GitHub (Nov 13, 2011): Comment created by @beberlei: This is deferred explicit related it seems.
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2011):

Comment created by @beberlei:

Verified

@doctrinebot commented on GitHub (Nov 13, 2011): Comment created by @beberlei: Verified
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2011):

Comment created by @beberlei:

Hm no, it works for me.

See e8eda4aeae and reopen if you can make it fail.

@doctrinebot commented on GitHub (Nov 13, 2011): Comment created by @beberlei: Hm no, it works for me. See https://github.com/doctrine/doctrine2/commit/e8eda4aeae3a24c52a0b69d01946b93c5a9cba27 and reopen if you can make it fail.
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2011):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#1834