framework/db/CDbMigration.php
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete=null, $update=null)
	{
		echo "    > add foreign key $name: $table (".(is_array($columns) ? implode(',', $columns) : $columns).
			 ") references $refTable (".(is_array($refColumns) ? implode(',', $refColumns) : $refColumns).") ...";
		$time=microtime(true);
		$this->getDbConnection()->createCommand()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
		echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
	}
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete=null, $update=null)
	{
		echo "    > add foreign key $name: $table (".(is_array($columns) ? implode(',', $columns) : $columns).
			 ") references $refTable (".(is_array($refColumns) ? implode(',', $refColumns) : $refColumns).") ...";
		$time=microtime(true);
		$this->getDbConnection()->createCommand()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
		echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
	}
public function addForeignKey ( $ name , $ table , $ columns , $ refTable , $ refColumns , $ delete = null , $ update = null ) { echo "    > add foreign key $name: $table (" . ( is_array ( $ columns ) ? implode ( ',' , $ columns ) : $ columns ) . ") references $refTable (" . ( is_array ( $ refColumns ) ? implode ( ',' , $ refColumns ) : $ refColumns ) . ") ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> addForeignKey ( $ name , $ table , $ columns , $ refTable , $ refColumns , $ delete , $ update ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds a SQL statement for adding a foreign key constraint to an existing table.
The method will properly quote the table and column names.
@param string $name the name of the foreign key constraint.
@param string $table the table that the foreign key constraint will be added to.
@param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $refTable the table that the foreign key references to.
@param string|array $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
Builds a SQL statement for adding a foreign key constraint to an existing table . The method will properly quote the table and column names .