Created
March 25, 2016 04:00
-
-
Save dcb9/fb48caec99c3e5881ee7 to your computer and use it in GitHub Desktop.
add comment function for MySQL ColumnSchemaBuilder in yii2 2.0.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\components; | |
class ColumnSchemaBuilder extends \yii\db\ColumnSchemaBuilder | |
{ | |
protected $comment; | |
/** | |
* @inheritdoc | |
*/ | |
public function __toString() | |
{ | |
return | |
$this->type . | |
$this->buildLengthString() . | |
$this->buildUnsignedString() . | |
$this->buildNotNullString() . | |
$this->buildUniqueString() . | |
$this->buildDefaultString() . | |
$this->buildCheckString() . | |
$this->buildCommentString(); | |
} | |
public function buildCommentString() | |
{ | |
return $this->comment ? " COMMENT '{$this->comment}'" : ''; | |
} | |
public function comment($comment) | |
{ | |
$this->comment = $comment; | |
return $this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'components' => [ | |
'db' => [ | |
// ... ... | |
// add these three lines | |
'schemaMap' => [ | |
'mysql' => 'common\components\MysqlSchema', | |
], | |
], | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\components; | |
use yii\db\mysql\Schema; | |
class MysqlSchema extends Schema | |
{ | |
/** | |
* @inheritdoc | |
*/ | |
public function createColumnSchemaBuilder($type, $length = null) | |
{ | |
return new ColumnSchemaBuilder($type, $length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment