/** * @return array - Category associated with parent */ public function getCategories() { return $this->hasMany(Category::className(), ['id' => 'categoryId'])->viaTable(CoreTables::TABLE_MODEL_CATEGORY, ['parentId' => 'id'], function ($query) { $modelCategory = CoreTables::TABLE_MODEL_CATEGORY; $query->onCondition(["{$modelCategory}.parentType" => $this->categoryType]); }); }
/** * @return Category - associated category */ public function getCategory() { return $this->hasOne(Category::className(), ['id' => 'categoryId']); }
/** * @return array - list of immediate child categories */ public function getCategories() { return $this->hasMany(Category::className(), ['parentId' => 'id']); }