Sets the entity that defines the relation. Sets the triggers
for before delete event.

@param Entity $entity

@return self
484570
public function setEntity(Entity $entity)
    {
        /** @var SharedEventManager $events */
        $events = $this->getContainer()->get('sharedEventManager');
        $name = $entity->getClassName();
        $events->attach(
            $name,
            Delete::BEFORE_DELETE,
            [$this, 'beforeDelete']
        );
        $events->attach(
            $name,
            Save::AFTER_SAVE,
            [$this, 'afterSave']
        );
        $this->getContainer()->set('sharedEventManager', $events);
        return parent::setEntity($entity);
    }
1063296
public function set(EntityInterface $entity)
    {
        $key = get_class($entity).'::'.$entity->getId();
        $this->getCache()->set($key, $entity);
        return $this;
    }
478894
protected function deleteEntity($entity)
    {
        $this->checkEntityType($entity);

        $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder());

        $delete->execute();
    }
599878
public function setEntity($entity)
    {
        if ($this->isRegistryEntity(get_class($entity))) {
            $this->classname = get_class($entity);
        }
        $this->entity = $entity;

        return $this;
    }
1057678
public function setEntity(Entity $entity)
    {

        /** @var SharedEventManager $events */
        $events = $this->getContainer()->get('sharedEventManager');
        $events->attach(
            get_class($entity),
            Delete::BEFORE_DELETE,
            array($this, 'onDelete')
        );
        $this->getContainer()->set('sharedEventManager', $events);
        return parent::setEntity($entity);
    }
129473
public function deleteEntity($entity)
    {
        if (!$this->isExtendedField($entity)) {
            return parent::deleteEntity($entity);
        }

        // Pre-delete event (same as core).
        $id    = $entity->getId();
        $event = $this->dispatchEvent('pre_delete', $entity);
        $this->getRepository()->deleteEntity($entity);

        $schema        = $this->getSchemaDefinition($entity->getName(), $entity->getType());
        $secure        = 'extendedFieldSecure' === $entity->getObject() ? '_secure' : '';
        $extendedTable = MAUTIC_TABLE_PREFIX.'lead_fields_leads_'.$schema['type'].$secure.'_xref';
        $column        = [
            'lead_field_id' => $entity->getId(),
        ];
        $this->em->getConnection()->delete(
            $extendedTable,
            $column
        );

        // Post-delete event (same as core).
        // set the id for use in events
        $entity->deletedId = $id;
        $this->dispatchEvent('post_delete', $entity, false, $event);
    }
84567
public function detach(object $entity): self
    {
        $this->container->detach(
            $this->extractIdentity($entity)
        );

        return $this;
    }
227406
public function deleteAllRelations($entity)
    {
        $this->deleteNotes($entity);
        $this->deleteAddresses($entity);
        $this->deleteEmails($entity);
        $this->deleteFaxes($entity);
        $this->deleteSocialMediaProfiles($entity);
        $this->deletePhones($entity);
        $this->deleteUrls($entity);
    }
739471
public function addEntity($entity)
    {
        $this->collection[] = $entity;
        $this->setCount(count($this->collection));

        return $this;
    }
632465
public function registerEntity(Entity $entity)
    {
        Logger::get()->debug('Registering entity ' . get_class($entity) . ":{$entity->id}...");
        self::$entities[get_called_class()][$entity->id] = $entity;
        Logger::get()->debug('Registered.');
    }
410084
public function init(Entity $entity) {
    // check entity
    if ($entity->getEntityName() !== ($class = $this->entityMeta->getClass())) {
      throw new \InvalidArgumentException('Das übergebene Entity für diesen Synchronizer kann nur vom Typ: '.$class.' sein. Ein Entity des Typs '.$entity->getEntityName().' wurde übergeben');
    }
    
    // check relation
    $collectionMeta = $this->getCollectionPropertyMeta();
    if (!$collectionMeta->isRelation()) {
      throw new \InvalidArgumentException(
        sprintf('Das Property %s von %s ist keine Collection. Das Property muss ManyToMany oder OneToMany sein',
                $this->collectionName, $this->entityMeta->getClass())
      );
    }
  }
969369
public function destroy(Entity $entity)
    {
        if ($entity->isExists()) {

            // enable logical delete ?
            if ($entity->hasAttribute('active')) {
                $attributes = [];
                $attributes['active'] = 0;
                if ($entity->hasAttribute('deleted_at')) $attributes['deleted_at'] = time();
                $this->update($attributes, $entity->getPrimaryValue());
            } else {
                $this->delete($entity->getPrimaryValue());
            }
        }
    }
274098
protected function registerEntity($entity)
    {
        Orm::getRepository($this->getParentEntity())
            ->getIdentityMap()
            ->set($entity);

        return $entity;
    }
1115769
public function remove($entity)
    {
        if ($this->evm->hasListeners(Events::preRemove)) {
            $this->evm->dispatchEvent(Events::preRemove, new Event\LifecycleEventArgs($entity, $this->sm));
        }

        $oid = spl_object_hash($entity);
        $this->scheduledForDelete[$oid] = $entity;

        if ($this->evm->hasListeners(Events::postRemove)) {
            $this->evm->dispatchEvent(Events::postRemove, new Event\LifecycleEventArgs($entity, $this->sm));
        }
    }
858144
public function remove($entity)
    {
        $idAccessorRegistry = $this->unitOfWork->getEntityRegistry()->getIdAccessorRegistry();
        $entityId           = $idAccessorRegistry->getEntityId($entity);

        $this->updateMap();

        if (!in_array($entityId, $this->map)) {
            throw new EntityNotFoundException;
        }

        $colJoinName = $this->relation->colJoinName();
        $mapObject   = $this->mapRepository->findOne()->with($colJoinName, Operator::EQUAL, $entityId)->getItem();
        $this->mapRepository->remove($mapObject);
        $this->map = array_diff($this->map, [$entityId]);
    }
1289693
public function delete($entity)
    {
        if (!$this->isRepositoryDeletable()) {
            throw $this->createNotDeletableException();
        }

        return $this->trigger(__FUNCTION__, [
            'entity' => $entity,
        ]);
    }
1333997
public function addReferencesToEntity($entity)
    {
        foreach ($this->strategies as $strategy) {
            $strategy->addReferencesToEntity($entity);
        }

        $this->objectManager->flush();
    }