setIdGeneratorType() public method

Sets the type of Id generator to use for the mapped class.
public setIdGeneratorType ( string $generatorType )
$generatorType string Generator type.
 /**
  * @param  \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
  * @param  string                                               $document
  * @param  array                                                $fields
  * @param  Boolean                                              $withRepository
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
 {
     $config = $this->documentManager->getConfiguration();
     $config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
     $documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
     $documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
     if (file_exists($documentPath)) {
         throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
     }
     $class = new ClassMetadataInfo($documentClass);
     if ($withRepository) {
         $class->setCustomRepositoryClass($documentClass . 'Repository');
     }
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $documentGenerator = $this->getDocumentGenerator();
     $documentCode = $documentGenerator->generateDocumentClass($class);
     $this->filesystem->mkdir(dirname($documentPath));
     file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
     }
 }
 public function generateBookDocumentFixture()
 {
     $metadata = new ClassMetadataInfo($this->namespace . '\\DocumentGeneratorBook');
     $metadata->namespace = $this->namespace;
     $metadata->customRepositoryClassName = $this->namespace . '\\DocumentGeneratorBookRepository';
     $metadata->collection = 'book';
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'status', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $metadata->mapOneReference(array('fieldName' => 'author', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorAuthor'));
     $metadata->mapManyReference(array('fieldName' => 'comments', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorComment'));
     $metadata->addLifecycleCallback('loading', 'postLoad');
     $metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     $this->generator->writeDocumentClass($metadata, $this->tmpDir);
     return $metadata;
 }