2
在我的項目中,我試圖通過調用關係uisng with()
返回相關數據,問題是當我設置limit()
關係不是數據返回。Yii2活動記錄:使用關係限制返回什麼也沒有
到目前爲止我的代碼: 關係
public function getRequestNoteLess(){
return $this->hasMany(RequestNote::className(), ['request_id'=>'id'])
->orderBy(['is_admin'=>SORT_DESC,'id'=>SORT_DESC])
->limit(3);
}
查詢
$out = Request::find()->select(['id','IF('.$t.' = 0, 0, 1) as userType','agent','id', 'source','reference',
'type','bedrooms','agent', 'size','budget',
'interested', 'full_name','phone','email',
'note','for','furnished', 'user_id','updated_by',
'inserted_at','updated_at', 'price','showed','offered',
'status','phone2','phone3', 'area','priority' ,'feed_back'])->where($where)->with('sources')->with('exchange')->with(['agen'=>function($q){$q->select(['username','id']);}])->with(['requestNoteLess'=>function($q){$q->select('*')->limit(3)->all();}])->orderBy(['id'=>SORT_DESC])->groupBy(['id'])->limit(300)->asArray()->all();
return json_encode($out);
而當你刪除所有工作正常的限度(只是沒有限制)? – robsch
是這發生了什麼@robsch –
你是通過'ActiveDataProvider'加載你的數據並在'GridView'中使用它嗎? 如果你的答案是肯定的,你應該在'ActiveDataProvider'類中配置'pageSize' – ThanhPV