Truncating All Tables in Doctrine

A quick script I use to truncate all entities registered in Doctrine:

$connection = $entityManager->getConnection();
$schemaManager = $connection->getSchemaManager();
$tables = $schemaManager->listTables();
$query = '';

foreach($tables as $table) {
    $name = $table->getName();
    $query .= 'TRUNCATE ' . $name . ';';
}
$connection->executeQuery($query, array(), array());
comments powered by Disqus