S
S
Sergei Iamskoi2020-01-11 23:42:35
Doctrine ORM
Sergei Iamskoi, 2020-01-11 23:42:35

How to specify that a field is autoincrement?

When using annotations on an entity, everything is simple:

/**
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="SEQUENCE")
 * @ORM\SequenceGenerator(sequenceName="id", initialValue=1)
 * @ORM\Column(type="integer")
 */
 private int $id;

But how to do it for Php mapping ? When the description of the fields is in an adjacent file.
<?php
/** @var ClassMetadata $metadata */

use Doctrine\Persistence\Mapping\ClassMetadata;

$metadata->mapField([
    'id' => true,
    'fieldName' => 'id',
    'type' => 'integer',
]);

I did not find any docks on this issue, Google did not help either (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergei Iamskoi, 2020-01-12
@syamskoy

Found in code:

$metadata->setIdGeneratorType($metadata::GENERATOR_TYPE_AUTO);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question