/** * Executes all operations * * @param callable $exceptionHandler */ public function flush(callable $exceptionHandler = null) { $this->executeTransaction(function () { foreach ($this->objectsToSave as $objects) { if (count($objects) == 1) { $this->orm->save($objects[0]); } else { $this->orm->saveAll($objects); } } foreach ($this->objectsToDelete as $objects) { if (count($objects) == 1) { $this->orm->delete($objects[0]); } else { $this->orm->deleteAll($objects); } } }, $exceptionHandler); $this->objectsToSave = []; $this->objectsToDelete = []; }
public function testLoadMany() { $object = new ExtendedDataObject(); $object->setMyColumn('many-to-one'); $this->repository->save($object); $otherObjects = []; $softDeleted = new OtherDataObject(); $otherObjects[] = $softDeleted->setName('Other object (soft deleted)')->setExtendedDataObjectId($object->getId()); $otherObject = new OtherDataObject(); $otherObjects[] = $otherObject->setName('Other object many-to-one 1')->setExtendedDataObjectId($object->getId()); $otherObject = new OtherDataObject(); $otherObjects[] = $otherObject->setName('Other object many-to-one 2')->setExtendedDataObjectId($object->getId()); $this->objectMapper->saveAll($otherObjects); $this->objectMapper->delete($softDeleted); /** @var OtherDataObject[] $return */ $return = $this->repository->loadMany([$object], OtherDataObject::class); $this->assertCount(2, $return); $this->assertInstanceOf(OtherDataObject::class, $return[$otherObject->getId()]); $loadedOtherObjects = $object->getOtherDataObjects(); $this->assertCount(2, $loadedOtherObjects); $this->assertEquals($otherObject->getId(), $loadedOtherObjects[1]->getId()); $this->assertEquals($otherObject->getName(), $loadedOtherObjects[1]->getName()); }