Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1496

OrphanRemove does not work when using clear() without initializing the collection before

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.1.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Collection items (marked with orphanRemoval=true) are not removed from the database correctly if
      1. the collection is not initialized
      2. we now call ->clear() on it.

      I think the problem is that PersistentCollection::clear() iterates through the uninitialized collection which is empty in this case. Thus the scheduleOrphanRemoval() method is never called.

      The best example is within the doctrine 2 documentation: http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-associations.html#orphan-removal . Calling $this->addresses->clear() raises this bug.

      I'm currently helping myself by fixing the situation with accessing the elements of the collection before calling ->clear().

        Activity

        Hide
        Benjamin Eberlei added a comment -

        fixed and merged into 2.1.x

        Show
        Benjamin Eberlei added a comment - fixed and merged into 2.1.x

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Georg Wächter
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: