/** * Get cache model * * @since 0.0.1 * @return {object} */ protected function getCacheTarget($type) { switch ($type) { case static::TYPE_CATEGORY: $cache_id = $this->category_id; $classname = SiteCategory::classname(); break; case static::TYPE_ARTICLE: $cache_id = $this->article_id; $classname = SiteArticle::classname(); break; } if (!$cache_id && $this->getOldAttribute('type') == $type) { $cache_id = $this->getOldAttribute('target_id'); } return $classname::findOne(['id' => $cache_id, 'site_id' => $this->site_id]); }
/** * Get articles belongs it * * @since 0.0.1 * @return {array} */ public function getArticles() { return $this->hasMany(SiteArticle::classname(), ['category_id' => 'id']); }