本文整理汇总了PHP中yii\db\Migration::addForeignKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::addForeignKey方法的具体用法?PHP Migration::addForeignKey怎么用?PHP Migration::addForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Migration
的用法示例。
在下文中一共展示了Migration::addForeignKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
public function install()
{
parent::install();
$migration = new Migration();
$migration->createTable($this->getTable(), ['id' => Schema::TYPE_PK, 'object_id' => Schema::TYPE_INTEGER, 'term_id' => Schema::TYPE_BIGINT, 'value' => Schema::TYPE_STRING]);
if ($migration->db->driverName === 'mysql') {
$migration->addForeignKey('fk_' . $this->getTable() . '_' . $this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE');
$migration->addForeignKey('fk_' . $this->getTable() . '_' . TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE');
}
}
示例2: actionUpdate
/**
* Update ip-geo-base data
*
* @throws \yii\base\Exception
*/
public function actionUpdate()
{
$migrate = new Migration();
$migrate->dropForeignKey('fk-geobase_contact-geobase_city_id', 'geobase_contact');
$ipGeoBase = new IpGeoBase();
$ipGeoBase->updateDB();
$migrate->addForeignKey('fk-geobase_contact-geobase_city_id', 'geobase_contact', 'geobase_city_id', 'geobase_city', 'id', 'CASCADE', 'CASCADE');
}
示例3: runRelations
/**
* Relate creations
* @return bool
*/
public function runRelations()
{
$result = true;
foreach ($this->relations as $_nextRelation) {
try {
if ($this->hideMigrationOutput) {
ob_start();
}
$result = $this->migrationClass->addForeignKey($_nextRelation['fk_name'], $_nextRelation['table_name'], $_nextRelation['field'], $_nextRelation['related_table'], $_nextRelation['related_field'], 'RESTRICT', 'CASCADE') && $result;
if ($this->hideMigrationOutput) {
ob_clean();
ob_flush();
}
} catch (\yii\db\Exception $expt) {
}
}
return $result;
}
示例4: addForeignKey
/**
* @inheritdoc
* Note: tables will be auto pefixied if [[$autoWrapTableNames]] is true.
*/
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
$table = $this->autoWrappedTableName($table);
$refTable = $this->autoWrappedTableName($refTable);
return parent::addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
}
示例5: addForeignKey
/**
* @inheritdoc
* @param string|null $name
*/
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
if (is_null($name)) {
$name = implode('-', array_merge((array) $table, (array) $columns));
}
if (is_null($delete)) {
$delete = static::RESTRICT;
}
if (is_null($update)) {
$update = static::NO_ACTION;
}
parent::addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
}
示例6: apply
public function apply()
{
return $this->migrate->addForeignKey($this->getName(), $this->getSourceTable(), $this->getSourceColumn(), $this->getRefTable(), $this->getRefColumn(), $this->getOnDelete(), $this->getOnUpdate());
}
示例7: addForeignKeyWithoutIndex
/**
* Builds a SQL statement for adding a foreign key constraint to an existing table (without index creation).
* 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 use an array.
* @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 use an array.
* @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
*
* @see addForeignKey
*/
public function addForeignKeyWithoutIndex($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
parent::addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
}
示例8: addForeignKey
/**
* 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 $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 use an array.
* @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 use an array.
* @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
* @param string $name the name of the foreign key constraint.
*/
public function addForeignKey($table, $columns, $refTable, $refColumns, $delete = 'CASCADE', $update = 'CASCADE', $name = null)
{
$name = $name ?: $this->getNameForeignKey($table, $columns);
parent::addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
}
示例9: addForeignKey
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
if (is_null($name)) {
$name = self::formFkName($table, $columns, $refTable, $refColumns);
}
return parent::addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update);
}