Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1630

Get PersistentCollection::getDeleteDiff is empty when collection changes from 1 item to zero items

    Details

    • Type: Bug
    • Status: Awaiting Feedback
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony2

      Activity

      lmcd Lee created issue -
      Hide
      deeky666 Steve Müller added a comment - - edited

      Same problem here. I wanted to write some unit tests, checking the entity relations and ran into exactly the same problem. Maybe my code can provide some more information (Group entity is the owning side, role entity is the inverse side):

      WHAT DOES NOT WORK:

              /**
               * Test ArrayCollection
               */
              $group = new Group('Group Test');
              $em->persist($group);
              $em->flush();
      
              $groups = new ArrayCollection();
              $groups->add($group);
      
              $this->role->setGroups($groups);
      
              $this->assertEquals($groups, $this->role->getGroups());
      
              /**
               * Test PersistentCollection
               */
              $em->persist($this->role);
              $em->flush();
      
              $groups = $this->role->getGroups();
              $groups->removeElement($group); // first remove element before adding a new one
      
              $group = new Group('Group Test 2');
              $em->persist($group);
              $em->flush();
              $groups->add($group);        
      
              $this->role->setGroups($groups);
      
              $this->assertEquals($groups, $this->role->getGroups());
      

      WHAT WORKS:

              /**
               * Test ArrayCollection
               */
              $group = new Group('Group Test');
              $em->persist($group);
              $em->flush();
      
              $groups = new ArrayCollection();
              $groups->add($group);
      
              $this->role->setGroups($groups);
      
              $this->assertEquals($groups, $this->role->getGroups());
      
              /**
               * Test PersistentCollection
               */
              $em->persist($this->role);
              $em->flush();
      
              $groups = $this->role->getGroups();
      
              $group2 = new Group('Group Test 2');
              $em->persist($group2);
              $em->flush();
              $groups->add($group2);  // first adding a new element before removing one
      
              $groups->removeElement($group);
      
              $this->role->setGroups($groups);
      
              $this->assertEquals($groups, $this->role->getGroups());
      

      Hope this helps in any way... I tried figuring it out on my own but I am too drunk right now xD

      Show
      deeky666 Steve Müller added a comment - - edited Same problem here. I wanted to write some unit tests, checking the entity relations and ran into exactly the same problem. Maybe my code can provide some more information (Group entity is the owning side, role entity is the inverse side): WHAT DOES NOT WORK: /** * Test ArrayCollection */ $group = new Group('Group Test'); $em->persist($group); $em->flush(); $groups = new ArrayCollection(); $groups->add($group); $ this ->role->setGroups($groups); $ this ->assertEquals($groups, $ this ->role->getGroups()); /** * Test PersistentCollection */ $em->persist($ this ->role); $em->flush(); $groups = $ this ->role->getGroups(); $groups->removeElement($group); // first remove element before adding a new one $group = new Group('Group Test 2'); $em->persist($group); $em->flush(); $groups->add($group); $ this ->role->setGroups($groups); $ this ->assertEquals($groups, $ this ->role->getGroups()); WHAT WORKS: /** * Test ArrayCollection */ $group = new Group('Group Test'); $em->persist($group); $em->flush(); $groups = new ArrayCollection(); $groups->add($group); $ this ->role->setGroups($groups); $ this ->assertEquals($groups, $ this ->role->getGroups()); /** * Test PersistentCollection */ $em->persist($ this ->role); $em->flush(); $groups = $ this ->role->getGroups(); $group2 = new Group('Group Test 2'); $em->persist($group2); $em->flush(); $groups->add($group2); // first adding a new element before removing one $groups->removeElement($group); $ this ->role->setGroups($groups); $ this ->assertEquals($groups, $ this ->role->getGroups()); Hope this helps in any way... I tried figuring it out on my own but I am too drunk right now xD
      Hide
      beberlei Benjamin Eberlei added a comment -

      Thanks for the report, formatted it

      Show
      beberlei Benjamin Eberlei added a comment - Thanks for the report, formatted it
      Hide
      beberlei Benjamin Eberlei added a comment -

      Which version is that btw?

      Show
      beberlei Benjamin Eberlei added a comment - Which version is that btw?
      Hide
      deeky666 Steve Müller added a comment -

      Occurs in version 2.1.6

      Show
      deeky666 Steve Müller added a comment - Occurs in version 2.1.6
      Hide
      beberlei Benjamin Eberlei added a comment -

      If group is the owning side, why do you only set Role::$groups? This has to be the other way around or not?

      Show
      beberlei Benjamin Eberlei added a comment - If group is the owning side, why do you only set Role::$groups? This has to be the other way around or not?
      Hide
      beberlei Benjamin Eberlei added a comment -

      @Steve

      I cannot reproduce your issue.

      Attached is a test script.

      Your code is very weird btw, why are you getting and setting groups collection? It is passed by reference so you can just have something like $role->addGroup() and $role->removeGroup() and encapsulate the logic?

      Also your tests are pretty useless, you check if two variables which are the same reference to the same collection are the same. Which should always be true.

      @Lee

      Can you provide more details? I cant verify this without more details.

      Show
      beberlei Benjamin Eberlei added a comment - @Steve I cannot reproduce your issue. Attached is a test script. Your code is very weird btw, why are you getting and setting groups collection? It is passed by reference so you can just have something like $role->addGroup() and $role->removeGroup() and encapsulate the logic? Also your tests are pretty useless, you check if two variables which are the same reference to the same collection are the same. Which should always be true. @Lee Can you provide more details? I cant verify this without more details.
      beberlei Benjamin Eberlei made changes -
      Field Original Value New Value
      Priority Major [ 3 ] Minor [ 4 ]
      beberlei Benjamin Eberlei made changes -
      Attachment DDC1630Test.php [ 11164 ]
      beberlei Benjamin Eberlei made changes -
      Workflow jira [ 13405 ] jira-feedback [ 14019 ]
      beberlei Benjamin Eberlei made changes -
      Workflow jira-feedback [ 14019 ] jira-feedback2 [ 15883 ]
      beberlei Benjamin Eberlei made changes -
      Workflow jira-feedback2 [ 15883 ] jira-feedback3 [ 18139 ]
      beberlei Benjamin Eberlei made changes -
      Status Open [ 1 ] Awaiting Feedback [ 10000 ]
      Anonymous made changes -
      Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
      asm89 Alexander made changes -
      Status In Progress [ 3 ] Awaiting Feedback [ 10000 ]
      Hide
      asm89 Alexander added a comment -

      Can anyone provide us with more feedback?

      Show
      asm89 Alexander added a comment - Can anyone provide us with more feedback?

      This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

      • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-1630}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

        People

        • Assignee:
          beberlei Benjamin Eberlei
          Reporter:
          lmcd Lee
        • Votes:
          2 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated: