Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1461

Possible Regression with OneToOne relation

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.2
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Do you know when this started to happen ?

        Show
        Benjamin Eberlei added a comment - Do you know when this started to happen ?
        Hide
        Johannes Schmitt added a comment - - edited

        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.

        Show
        Johannes Schmitt added a comment - - edited 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.
        Hide
        Benjamin Eberlei added a comment -

        This is deferred explicit related it seems.

        Show
        Benjamin Eberlei added a comment - This is deferred explicit related it seems.
        Hide
        Benjamin Eberlei added a comment -

        Verified

        Show
        Benjamin Eberlei added a comment - Verified
        Hide
        Benjamin Eberlei added a comment -

        Hm no, it works for me.

        See https://github.com/doctrine/doctrine2/commit/e8eda4aeae3a24c52a0b69d01946b93c5a9cba27 and reopen if you can make it fail.

        Show
        Benjamin Eberlei added a comment - Hm no, it works for me. See https://github.com/doctrine/doctrine2/commit/e8eda4aeae3a24c52a0b69d01946b93c5a9cba27 and reopen if you can make it fail.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Johannes Schmitt
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: