首页 > 其他 > 详细

yii2 一对多关系的对分页造成的影响

时间:2018-03-05 13:32:03      阅读:259      评论:0      收藏:0      [点我收藏+]
下面代码中关联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中建立关联时限定:
  1. public function getBooks()
  2.     {
  3.         return $this->hasMany(Item::className(), [‘owner_id‘ => ‘id‘])->onCondition([‘category_id‘ => 1]);
  4.     }

 2.代码中限定:方法如上:

yii2 一对多关系的对分页造成的影响

原文:https://www.cnblogs.com/qq1069284034/p/8508368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!