/** * Deletes an entity from the repo * * @param object $entity The entity to delete * * @return void * * @throws OrmException if the entity could not be deleted */ 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]); }
/** * Delete a tag for a master * * The system will detect the change and delete the entry in the map. * The tag itself will not be affected. */ public function testDeleteATagForAMaster() { $this->restoreData(['masters', 'maps', 'tags']); $repo = $this->repo[Master::class]; $master = $repo->getById(1); $tag = $master->tags->getById(1); $master->tags->remove($tag); $this->unitOfWork->commit(); $this->entityRegistry->clear(); $master = $repo->getById(1); $tags = $master->tags->findAll()->columns('tag')->getItems(); $this->assertEquals(['Tag 2', 'Tag 3'], $tags); $tagRepo = $this->repo[Tag::class]; $tag = $tagRepo->getById(1); $this->assertEquals('Tag 1', $tag->tag); }
/** * Create a new entity * * @param array $row A hash with the properties for the new entity * * @return object */ public function createFromArray(array $row) { $entities = $this->unitOfWork->getEntityRegistry()->getEntityBuilder()->castToEntity([$row], $this->className); return array_shift($entities); }
/** * Sets the database transactor * * @param TransactionInterface $transactor The transactor to use */ public function setTransactor(TransactionInterface $transactor) { $this->unitOfWork->setTransactor($transactor); }
/** * @testdox commit() is a proxy for commit() on the unit of work */ public function testCommit() { $this->unitOfWork->expects($this->once())->method('commit'); $this->repo->commit(); }