hasMany(Positions::class, ['group_id' => 'id'])->orderBy(['order_index' => SORT_ASC])->all(); } public function getPositionsCount() { return $this->hasMany(Positions::class, ['group_id' => 'id'])->count(); } public function getArticleModel() { return $this->hasOne(Articles::class, ['key' => 'position_article_key']); } public function getArticle() { if ($this->position_article_key) { $table = explode('_', $this->position_article_key); switch ($table[0]) { case 'news': return $this->articleModel->news; case 'events': return $this->articleModel->events; case 'campaigns': return $this->articleModel->campaigns; } } } }