src/DoctrineModule/Stdlib/Hydrator/Strategy/AllowRemoveByReference.php
public function hydrate($value)
    {
        $collection      = $this->getCollectionFromObjectByReference();
        $collectionArray = $collection->toArray();

        $toAdd    = array_udiff($value, $collectionArray, array($this, 'compareObjects'));
        $toRemove = array_udiff($collectionArray, $value, array($this, 'compareObjects'));

        foreach ($toAdd as $element) {
            $collection->add($element);
        }

        foreach ($toRemove as $element) {
            $collection->removeElement($element);
        }

        return $collection;
    }
public function hydrate($value)
    {
        $collection      = $this->getCollectionFromObjectByReference();
        $collectionArray = $collection->toArray();

        $toAdd    = array_udiff($value, $collectionArray, array($this, 'compareObjects'));
        $toRemove = array_udiff($collectionArray, $value, array($this, 'compareObjects'));

        foreach ($toAdd as $element) {
            $collection->add($element);
        }

        foreach ($toRemove as $element) {
            $collection->removeElement($element);
        }

        return $collection;
    }
{@inheritDoc}