Last active
December 17, 2015 19:58
-
-
Save tomzx/5663921 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
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) | |
{ | |
$def = ''; | |
if ($foreignKey->getConstraint()) { | |
$def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint()); | |
} | |
$columnNames = array(); | |
foreach ($foreignKey->getColumns() as $column) { | |
$columnNames[] = $this->quoteColumnName($column); | |
} | |
$def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')'; | |
$refColumnNames = array(); | |
foreach ($foreignKey->getReferencedColumns() as $column) { | |
$refColumnNames[] = $this->quoteColumnName($column); | |
} | |
$def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')'; | |
if ($foreignKey->getOnDelete()) { | |
$def .= ' ON DELETE ' . $foreignKey->getOnDelete(); | |
} | |
if ($foreignKey->getOnUpdate()) { | |
$def .= ' ON UPDATE ' . $foreignKey->getOnUpdate(); | |
} | |
return $def; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment