protected function deleteManyToManyReferences(Entity $entity)
    {
        foreach ($this->definition->getService()->getEntities() as $entityName) {
            $data = $this->definition->getService()->getData($entityName);
            foreach ($data->getDefinition()->getFieldNames(true) as $field) {
                if ($data->getDefinition()->getType($field) == 'many') {
                    $otherEntity = $data->getDefinition()->getSubTypeField($field, 'many', 'entity');
                    $otherData   = $this->definition->getService()->getData($otherEntity);
                    if ($entity->getDefinition()->getTable() == $otherData->getDefinition()->getTable()) {
                        $thatField    = $data->getDefinition()->getSubTypeField($field, 'many', 'thatField');
                        $queryBuilder = $this->database->createQueryBuilder();
                        $queryBuilder
                            ->delete('`'.$field.'`')
                            ->where('`'.$thatField.'` = ?')
                            ->setParameter(0, $entity->get('id'))
                            ->execute()
                        ;
                    }
                }
            }
        }
    }