public function up() { $this->createTable(Category::tableName(), ['id' => Schema::TYPE_PK, 'owner_id' => $this->integer(), 'status' => Schema::TYPE_SMALLINT, 'title' => Schema::TYPE_STRING, 'name' => Schema::TYPE_STRING, 'image' => Schema::TYPE_STRING, 'content' => Schema::TYPE_TEXT, 'lft' => Schema::TYPE_INTEGER, 'rgt' => Schema::TYPE_INTEGER, 'depth' => Schema::TYPE_INTEGER]); $this->createTable(CategoryToItem::tableName(), ['category_id' => Schema::TYPE_INTEGER, 'item_id' => Schema::TYPE_INTEGER]); MigrationHelper::addForeignKey(CategoryToItem::tableName(), 'category_id', Category::tableName(), 'id', 'CASCADE', 'CASCADE'); MigrationHelper::addForeignKey(CategoryToItem::tableName(), 'item_id', Item::tableName(), 'id', 'CASCADE', 'CASCADE'); }
/** * @inheritdoc */ public function run() { return $this->render($this->viewName, ['model' => $this->model, 'items' => $this->model->linkList($this->field), 'admin' => $this->admin]); }
public function down() { $this->dropTable(Item::tableName()); }
public function run() { $items = Item::childClass(true)->search()->andWhere(['status' => $this->statuses])->orderBy(['created_at' => SORT_DESC])->limit($this->limit)->all(); return $this->render($this->viewName, compact('items')); }
/** * @return ActiveQuery */ public function getItems() { return static::hasMany(Item::childClass(), ['id' => 'item_id'])->via('categoryToItems'); }