-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added foreignKey
method for yii\db\ColumnSchemaBuilder
#13018
Added foreignKey
method for yii\db\ColumnSchemaBuilder
#13018
Conversation
kfreiman
commented
Nov 16, 2016
Q | A |
---|---|
Is bugfix? | no |
New feature? | yes |
Breaks BC? | no |
Tests pass? | yes |
Fixed issues | #13016, #8163 |
|
@@ -265,6 +265,18 @@ public function createTable($table, $columns, $options = null) | |||
if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) { | |||
$this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute(); | |||
} | |||
|
|||
if ($type instanceof ColumnSchemaBuilder && $type->foreignKeyName !== null) { | |||
$this->db->createCommand()->addForeignKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't also create the index key?
/** | ||
* @var string the name of the foreign key constraint. | ||
*/ | ||
public $foreignKeyName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to make them public and not protected since only foreignKey()
method can modify them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not ok or not bad that the properties are public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not OK.
* @param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL | ||
* @return $this | ||
*/ | ||
public function foreignKey($foreignKeyName, $refTable, $refColumn, $delete=null, $update=null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this name clashes with an existing functionality on the generator http://www.yiiframework.com/doc-2.0/guide-db-migrations.html#foreign-keys
Related: I think this should be rewritten to allow define FK for SQLite - FK definition should be injected into |