public function up()
 {
     //初始化设置表
     $tableName = Config::tableName();
     $this->createTable($tableName, ['name' => Schema::TYPE_STRING . "(64) NOT NULL COMMENT '名称'", 'value' => Schema::TYPE_TEXT . " NOT NULL COMMENT '保存的值'", 'PRIMARY KEY (name)'], $this->tableOptions);
     //附件表
     $tableName = Storage::tableName();
     $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'uid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户id'", 'name' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '原始文件名'", 'path' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '保存路径'", 'size' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '文件大小'", 'mime_type' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '文件类型'", 'bin' => Schema::TYPE_STRING . "(30) NOT NULL DEFAULT '' COMMENT '存储容器'", 'type' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '所属类型'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '附件存储状态'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'"], $this->tableOptions);
     $this->createIndex('uid', $tableName, 'uid');
     $this->createIndex('type', $tableName, ['type', 'id']);
     //标签表
     $tableName = Tag::tableName();
     $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'name' => Schema::TYPE_STRING . "(64) NOT NULL COMMENT '标签名'", 'icon' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '标签图标'", 'description' => Schema::TYPE_TEXT . " NOT NULL COMMENT '版块介绍'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '标签状态'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'"]);
     $this->createIndex('name', $tableName, 'name', true);
     $this->createIndex('status', $tableName, ['status', 'id']);
     //标签数据表
     $tableName = TagItem::tableName();
     $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'tid' => Schema::TYPE_STRING . "(64) NOT NULL COMMENT '标签id'", 'target_id' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '目标id'", 'target_type' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '目标类型'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'"]);
     $this->createIndex('item', $tableName, ['tid', 'target_id', 'target_type'], true);
     $this->createIndex('target_type', $tableName, ['target_type', 'target_id']);
 }
示例#2
0
 /**
  * 获取帖子标签记录
  * @return mixed
  */
 public function getTagItems()
 {
     return $this->hasMany(TagItem::className(), ['target_id' => 'id'])->andWhere(['target_type' => static::TYPE]);
 }
示例#3
0
 public function getItems()
 {
     return $this->hasMany(TagItem::className(), ['id' => 'tid']);
 }