下面代码中关联descies时,匹配较多,造成分页数不对,需要加条件限制:
$model = User::find()
->joinWith(‘app‘)
->joinWith([‘descies‘ => function($query){
return $query->where([‘user_desc_type_id‘=>7]);
}])
->where($condition)
->andFilterWhere($condition_pay_start)
->andFilterWhere($condition_sex);
$pagination = new Pagination([
‘defaultPageSize‘ => 10,
‘totalCount‘ => $model->count(),
]);
1.可在model中建立关联时限定:
- public function getBooks()
- {
- return $this->hasMany(Item::className(), [‘owner_id‘ => ‘id‘])->onCondition([‘category_id‘ => 1]);
- }
2.代码中限定:方法如上: