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

persist() public method

Persists a document as part of the current unit of work.
public persist ( object $document )
$document object The document to persist.
    public function persist($document)
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        if ($class->isMappedSuperclass || $class->isQueryResultDocument) {
            throw MongoDBException::cannotPersistMappedSuperclass($class->name);
        }
        $visited = array();
        $this->doPersist($document, $visited);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Tells the DocumentManager to make an instance managed and persistent.
  *
  * The document will be entered into the database at or before transaction
  * commit or as a result of the flush operation.
  *
  * NOTE: The persist operation always considers documents that are not yet known to
  * this DocumentManager as NEW. Do not pass detached documents to the persist operation.
  *
  * @param object $document The instance to make managed and persistent.
  */
 public function persist($document)
 {
     if (!is_object($document)) {
         throw new \InvalidArgumentException(gettype($document));
     }
     $this->errorIfClosed();
     $this->unitOfWork->persist($document);
 }
UnitOfWork