@@ 1053-1077 (lines=25) @@ | ||
1050 | * @param \Phinx\Db\Table\ForeignKey $foreignKey |
|
1051 | * @return string |
|
1052 | */ |
|
1053 | protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) |
|
1054 | { |
|
1055 | $def = ''; |
|
1056 | if ($foreignKey->getConstraint()) { |
|
1057 | $def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint()); |
|
1058 | } else { |
|
1059 | $columnNames = []; |
|
1060 | foreach ($foreignKey->getColumns() as $column) { |
|
1061 | $columnNames[] = $this->quoteColumnName($column); |
|
1062 | } |
|
1063 | $def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')'; |
|
1064 | $refColumnNames = []; |
|
1065 | foreach ($foreignKey->getReferencedColumns() as $column) { |
|
1066 | $refColumnNames[] = $this->quoteColumnName($column); |
|
1067 | } |
|
1068 | $def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')'; |
|
1069 | if ($foreignKey->getOnDelete()) { |
|
1070 | $def .= ' ON DELETE ' . $foreignKey->getOnDelete(); |
|
1071 | } |
|
1072 | if ($foreignKey->getOnUpdate()) { |
|
1073 | $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate(); |
|
1074 | } |
|
1075 | } |
|
1076 | ||
1077 | return $def; |
|
1078 | } |
|
1079 | } |
|
1080 |
@@ 1040-1063 (lines=24) @@ | ||
1037 | * |
|
1038 | * @return string |
|
1039 | */ |
|
1040 | protected function getForeignKeySqlDefinition( ForeignKey $foreignKey ) { |
|
1041 | $def = ''; |
|
1042 | if ( $foreignKey->getConstraint() ) { |
|
1043 | $def .= ' CONSTRAINT ' . $this->quoteColumnName( $foreignKey->getConstraint() ); |
|
1044 | } |
|
1045 | $columnNames = []; |
|
1046 | foreach ( $foreignKey->getColumns() as $column ) { |
|
1047 | $columnNames[] = $this->quoteColumnName( $column ); |
|
1048 | } |
|
1049 | $def .= ' FOREIGN KEY (' . implode( ',', $columnNames ) . ')'; |
|
1050 | $refColumnNames = []; |
|
1051 | foreach ( $foreignKey->getReferencedColumns() as $column ) { |
|
1052 | $refColumnNames[] = $this->quoteColumnName( $column ); |
|
1053 | } |
|
1054 | $def .= ' REFERENCES ' . $this->quoteTableName( $foreignKey->getReferencedTable()->getName() ) . ' (' . implode( ',', $refColumnNames ) . ')'; |
|
1055 | if ( $foreignKey->getOnDelete() ) { |
|
1056 | $def .= ' ON DELETE ' . $foreignKey->getOnDelete(); |
|
1057 | } |
|
1058 | if ( $foreignKey->getOnUpdate() ) { |
|
1059 | $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate(); |
|
1060 | } |
|
1061 | ||
1062 | return $def; |
|
1063 | } |
|
1064 | ||
1065 | /** |
|
1066 | * Describes a database table. This is a MySQL adapter specific method. |