Sokil\Mongo\Document::createReference PHP Method

createReference() public method

Get reference to document
public createReference ( ) : array
return array
    public function createReference()
    {
        $documentId = $this->getId();
        if (null === $documentId) {
            throw new Exception('Document must be stored to get DBRef');
        }
        return $this->getCollection()->getMongoCollection()->createDBRef($documentId);
    }

Usage Example

Example #1
0
 /**
  * Push reference to list
  *
  * @param string $name
  * @param Document $document
  * @return Document
  */
 public function pushReference($name, Document $document)
 {
     return $this->push($name, $document->createReference());
 }