php - Reset Doctrine 2 ID -
i'm doing integration testing , can't directly set id entity. need is, somehow tell doctrine reset id 1.
when call flush ids 20, 21, 22,23.
i have tried deleting table, reseting identity or thread nothing helps.
my code:
public function testfindingallorderedbydefault() { /** @var $bundles bundle[] */ $bundles = $this->repository->findall(); $this->assertcount(2, $bundles); $this->assertsame(1, $bundles[0]->getid()); $this->assertsame(2, $bundles[1]->getid()); } protected function preparedatabase(entitymanager $entitymanager, connection $connection) { $connection->executequery('truncate bundle cascade'); $entitymanager->persist( (new bundle()) ->setprice(1200) ->setpricevat(5000) ->setdiscount(1000) ->setcurrency('czk') ); $entitymanager->persist( (new bundle()) ->setprice(1300) ->setpricevat(4000) ->setdiscount(500) ->setcurrency('eur') ); $entitymanager->flush(); }
thanks in advance.
the problem not doctrine related here. mysql keeps next available primary key stored in table meta-data. can "reset" or alter value executing alter table
query:
alter table your_table auto_increment = 1;
or, in doctrine migration:
public function up(schema $schema) { $this->connection->exec('alter table your_table auto_increment = 1'); }
if you're not using doctrine migration bundle, can write one-off script and, using entity manager:
$em->getconnection()->exec('alter table your_tbl auto_increment = 1');
Comments
Post a Comment