Run driver specific SQL to disable foreign key checks.
public disableForeignKeys ( ) : void | ||
return | void |
/** * Executes list of quries in one transaction. * * @param \Cake\Database\Connection $db Connection to run the SQL queries on. * @param array $queries List of SQL statements. * @return void */ protected function _execute($db, $queries = null) { $logQueries = $db->logQueries(); if ($logQueries) { $db->logQueries(false); } $db->transactional(function ($db) use($queries) { $db->disableForeignKeys(); foreach ($queries as $query) { $this->_io->out('.', 0); $db->execute($query)->closeCursor(); } $db->enableForeignKeys(); }); if ($logQueries) { $db->logQueries(true); } }
/** * Insert data into tables. * * @param \Cake\Database\Connection $db Connection to run the SQL queries on. * @param array $data List tables and rows. * @return void */ protected function _insert($db, $data = null) { $this->_io->out('Seeding ', 0); $operation = function ($db) use($data) { $db->disableForeignKeys(); foreach ($data as $table => $rows) { $this->_io->out('.', 0); $this->_beforeTableInsert($db, $table); $this->_insertTable($db, $table, $rows); $this->_afterTableInsert($db, $table); } $db->enableForeignKeys(); }; $this->_runOperation($db, $operation); $this->_io->out(); // New line }