src/Database/QueryBuilder/Commands/Alter.php
/**
	 * Adds a foreign key to the table.
	 *
	 * @param string|string[] $columns
	 * @param string $foreignTable
	 * @param string|string[] $foreignColumns
	 * @param string|null $onDelete
	 * @param string|null $onUpdate
	 * @return $this
	 */
Adds a foreign key to the table.
Adds a foreign key to the table .
public function addForeignKey($columns, $foreignTable, $foreignColumns, $onDelete = null, $onUpdate = null) {
		if (!is_array($columns)) $column = array($columns);
		if (!is_array($foreignColumns)) $foreignColumns = array($foreignColumns);
		$keyName = StringBuilder::formatColumnName(
			'fk_' . $this->table . '_' . implode('_', $columns) .
			'_' . $foreignTable . '_' . implode('_', $foreignColumns));
		$statement = sprintf(
			'ADD FOREIGN KEY %s (%s) REFERENCES %s (%s)',
			$keyName, $this->compileColumnList($columns),
			StringBuilder::formatTableName($this->builder->getPrefix() . $foreignTable),
			$this->compileColumnList($foreignColumns)
		);
		if (!is_null($onDelete)) $statement .= ' ON DELETE ' . strtoupper($onDelete);
		if (!is_null($onUpdate)) $statement .= ' ON UPDATE ' . strtoupper($onUpdate);
		$this->statements[] = $statement;
		return $this;
	}
public function addForeignKey ( $ columns , $ foreignTable , $ foreignColumns , $ onDelete = null , $ onUpdate = null ) { if ( ! is_array ( $ columns ) ) $ column = array ( $ columns ) ; if ( ! is_array ( $ foreignColumns ) ) $ foreignColumns = array ( $ foreignColumns ) ; $ keyName = StringBuilder :: formatColumnName ( 'fk_' . $ this -> table . '_' . implode ( '_' , $ columns ) . '_' . $ foreignTable . '_' . implode ( '_' , $ foreignColumns ) ) ; $ statement = sprintf ( 'ADD FOREIGN KEY %s (%s) REFERENCES %s (%s)' , $ keyName , $ this -> compileColumnList ( $ columns ) , StringBuilder :: formatTableName ( $ this -> builder -> getPrefix ( ) . $ foreignTable ) , $ this -> compileColumnList ( $ foreignColumns ) ) ; if ( ! is_null ( $ onDelete ) ) $ statement .= ' ON DELETE ' . strtoupper ( $ onDelete ) ; if ( ! is_null ( $ onUpdate ) ) $ statement .= ' ON UPDATE ' . strtoupper ( $ onUpdate ) ; $ this -> statements [ ] = $ statement ; return $ this ; }
Adds a foreign key to the table.
Adds a foreign key to the table .