Explicitly set Id with Doctrine when using “AUTO” strategy

前端 未结 7 705
时光说笑
时光说笑 2020-12-02 05:36

My entity uses this annotation for it\'s ID:

/**
 * @orm:Id
 * @orm:Column(type=\"integer\")
 * @orm:GeneratedValue(s         


        
7条回答
  •  清歌不尽
    2020-12-02 06:15

    Solution for Doctrine 2.5 and MySQL

    The "New solution" doesn't work with Doctrine 2.5 and MySQL. You have to use:

    $metadata = $this->getEntityManager()->getClassMetaData(Entity::class);
    $metadata->setIdGenerator(new AssignedGenerator());
    $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_‌​NONE);
    

    However I can only confirm that for MySQL,because I haven't tried any other DBMS yet.

提交回复
热议问题