/** @inheritdoc */ public function processClearIdentityMapAndCaches($areYouSure = NULL) { if ($areYouSure !== IModel::I_KNOW_WHAT_I_AM_DOING) { throw new LogicException('Do not call this method directly. Use IModel::clearIdentityMapAndCaches().'); } $this->identityMap->destroyAllEntities(); $this->mapper->clearCollectionCache(); }
public function remove($entity) { $entity = $entity instanceof IEntity ? $entity : $this->getById($entity); $this->identityMap->check($entity); foreach ($entity->getMetadata()->getProperties() as $property) { if ($property->relationshipType) { if (in_array($property->relationshipType, [PropertyMetadata::RELATIONSHIP_MANY_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE_DIRECTED])) { $entity->getProperty($property->name)->set(NULL, TRUE); } else { $entity->getValue($property->name)->set([]); } } } if ($entity->isPersisted() || $entity->getRepository(FALSE)) { $entity->fireEvent('onBeforeRemove'); if ($entity->isPersisted()) { $this->mapper->remove($entity); $this->identityMap->remove($entity->getPersistedId()); } $this->identityMap->detach($entity); $entity->fireEvent('onAfterRemove'); } return $entity; }