Created
January 30, 2020 02:03
-
-
Save wilcorrea/472bd0a492502491b32622eb32c1feca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BlaBlaBla extends Migration | |
{ | |
// ... up, down whatever | |
protected function existsForeignKey($table, $foreignKey) | |
{ | |
$sql = "SELECT KEY_COLUMN_USAGE.CONSTRAINT_NAME | |
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE | |
WHERE KEY_COLUMN_USAGE.TABLE_NAME = '{$table}' AND KEY_COLUMN_USAGE.COLUMN_NAME = '{$foreignKey}'"; | |
$command = $this->db->createCommand($sql); | |
return count($command->queryAll()) > 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment