Doctrine\ODM\MongoDB\UnitOfWork::scheduleForUpdate PHP Method

scheduleForUpdate() public method

Schedules a document for being updated.
public scheduleForUpdate ( object $document )
$document object The document to schedule for being updated.
    public function scheduleForUpdate($document)
    {
        $oid = spl_object_hash($document);
        if (!isset($this->documentIdentifiers[$oid])) {
            throw new \InvalidArgumentException('Document has no identity.');
        }
        if (isset($this->documentDeletions[$oid])) {
            throw new \InvalidArgumentException('Document is removed.');
        }
        if (!isset($this->documentUpdates[$oid]) && !isset($this->documentInsertions[$oid]) && !isset($this->documentUpserts[$oid])) {
            $this->documentUpdates[$oid] = $document;
        }
    }

Usage Example

 function it_schedules_owning_document_for_update_when_setting_element_by_key_in_the_collection(MongoDBODMUnitOfWork $uow, DocumentStub $document, ObjectRepository $repository, ClassMetadata $classMetadata, EntityStub $entity4, EntityStub $entity8, EntityStub $entity15, EntityStub $newEntity)
 {
     $classMetadata->getIdentifier()->willReturn(['id']);
     $repository->findBy(['id' => [4, 8, 15]])->willReturn([$entity4, $entity8, $entity15]);
     $uow->getDocumentState($document)->willReturn(MongoDBODMUnitOfWork::STATE_MANAGED);
     $uow->isScheduledForUpdate($document)->willReturn(false);
     $uow->scheduleForUpdate($document)->shouldBeCalled();
     $this->setOwner($document);
     $this->set(2, $newEntity);
 }
UnitOfWork