publicfunctiongetActiveComments(){return$this->hasMany(Comment::className(),['post_id'=>'id'])->active();}} 或者在执行关联查询的时候使用(on-the-fly