m161101_143541_blog_article_to_category.php
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
use yii\db\Migration;
class m161101_143541_blog_article_to_category extends Migration
{
public function up()
{
/**
* Create junction table to connect articles with categories
*/
$this->createTable(
'blog_article_to_category',
[
'blog_article_id' => $this->integer()
->notNull(),
'blog_category_id' => $this->integer()
->notNull(),
]
);
/**
* Add foreign keys and indexes for junction table
*/
$this->createIndex(
'blog_article_to_category_uk',
'blog_article_to_category',
[
'blog_article_id',
'blog_category_id',
],
true
);
$this->addForeignKey(
'blog_article_to_category_art_fk',
'blog_article_to_category',
'blog_article_id',
'blog_article',
'id',
'CASCADE',
'CASCADE'
);
$this->addForeignKey(
'blog_article_to_category_cat_fk',
'blog_article_to_category',
'blog_category_id',
'blog_category',
'id',
'CASCADE',
'CASCADE'
);
}
public function down()
{
$this->dropForeignKey('blog_article_to_category_cat_fk', 'blog_article_to_category');
$this->dropForeignKey('blog_article_to_category_art_fk', 'blog_article_to_category');
$this->dropIndex('blog_article_to_category_uk', 'blog_article_to_category');
$this->dropTable('blog_article_to_category');
}
}