private function addToChangeSet(
        EntityManagerInterface $em,
        ClassMetadata $metadata,
        $entity,
        array &$change_set
    ) {
        if (!isset($change_set[$metadata->rootEntityName])) {
            $change_set[$metadata->rootEntityName] = [];
        }

        if (!in_array($entity, $change_set[$metadata->rootEntityName], true)) {
            $change_set[$metadata->rootEntityName][] = $entity;

            // recursively find all changes
            $this->appendAssociations($em, $metadata, $entity, $change_set);
        }
    }