I have table with several foreign keys. I need to truncate this table and related tables using queryBuilder.
I have found two solutions:
So, I have tried to implement the first solution. According to this example :
$connection->executeQuery('SET FOREIGN_KEY_CHECKS = 0;');
$truncateSql = $platform->getTruncateTableSQL('table_name');
$connection->executeUpdate($truncateSql);
$connection->executeQuery('SET FOREIGN_KEY_CHECKS = 1;');
But if I need to implement this method for each PDO this would be a bit cumbersome.
The second solution looks like more compact, but I have no idea, how to do ALTER TABLE request correct, using queryBuilder.
So, my questions below:
- How to do ALTER TABLE request in Symfony2 using queryBuilder?
- What is the most compact way to do truncate table for each PDO?
- Is it any compact way to truncate not only current table, but each related table?
Thanks a lot for any help!
UPDATED: Also, I have found this, but this looks like out-of-date.
I have found some solution, but I'm not sure it's Symfony way. You can see my solution as answer below.