/**
  * @param QueryWriter $queryWriter
  * @param UnitOfWork  $uow
  * @param array       $set
  *
  * @return array
  */
 private function &processDocumentUpdates(QueryWriter $queryWriter, UnitOfWork $uow, array &$set)
 {
     $docs = [];
     $ordered = self::orderByType($uow->getDocumentUpdates(), $set);
     if (empty($ordered)) {
         return $docs;
     }
     foreach ($ordered as $class => $updates) {
         /** @var ClassMetadata $md */
         $md = $this->metadataFactory->getMetadataFor($class);
         if ($md->isEmbeddedDocument()) {
             continue;
         }
         foreach ($updates as $oid => $doc) {
             $id = $this->createDocVarReference($doc);
             $rid = $uow->getDocumentRid($doc);
             $data = $this->prepareData($md, $uow, $doc);
             $version = null;
             if ($md->version) {
                 $version = $md->reflFields[$md->version]->getValue($doc);
             }
             $queryWriter->addUpdateQuery($rid, $data, $id->toValue(), $version);
             $docs[] = [$id, $doc, $md];
         }
     }
     return $docs;
 }