public function updateCommentTotal() { $model = CommentInfo::find()->where(["entity" => $this->entity, "entity_id" => $this->entity_id])->one(); $total = Comment::activeCount($this->entity, $this->entity_id); if ($model == null && $total != 0) { $model = new CommentInfo(); $model->entity = $this->entity; $model->entity_id = $this->entity_id; $model->total = $total; $model->save(); } else { $model->total = $total; $model->save(); } }