2
私のプロジェクトでは、でリレーションを呼び出すことによって関連するデータを返そうとしていますが、返されたデータのリレーションに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'で使用していますか? あなたの答えがyesの場合、あなたは 'クラスのpageSize'' ActiveDataProvider' – ThanhPV