Yii2 hasMany 关联后加条件

当前模型类为活动表id,关联评论表的type_id,条件是评论表的type要等于2
public function getComment(){
return $this->hasMany(Comment::className(),['type_id'=>'id'])->onCondition([Comment::tableName().'.type'=>2]);
}
posted @ 2018-12-19 10:36  fpc  阅读(2086)  评论(0编辑  收藏  举报