private function loadIndirectReferenceCollection(PersistentCollection $collection)
 {
     $rows = $collection->getData();
     if (count($rows) === 0) {
         return;
     }
     $mapping = $collection->getMapping();
     $prop = $mapping['direction'] === 'in' ? 'out' : 'in';
     $rids = [];
     $results = [];
     $edgeRids = [];
     foreach ($rows as $row) {
         if (is_string($row)) {
             // edge RID
             $edgeRids[] = $row;
             continue;
         }
         // edge is loaded, so we
         $edgeRid = $row['@rid'];
         if (is_string($row[$prop])) {
             $rids[$row[$prop]][] = $edgeRid;
         } else {
             $results[$edgeRid] = $rows[$prop];
         }
     }
     // load edges and their immediate children (*:1)
     if ($edgeRids) {
         $loaded = $this->binding->query(sprintf('SELECT FROM [%s]', implode(',', $edgeRids)), -1, '*:1');
         $results = array_merge($results, self::extractVertexes($loaded, $prop));
     }
     if ($rids) {
         $loaded = $this->binding->query(sprintf('SELECT FROM [%s]', implode(',', array_keys($rids))));
         foreach ($loaded as $row) {
             $rid = $row['@rid'];
             foreach ($rids[$rid] as $edge) {
                 $results[$edge] = $row;
             }
         }
     }
     foreach ($results as $key => $data) {
         $document = $this->uow->getOrCreateDocument($data);
         $collection->set($key, $document);
     }
 }