fastadmin关联预载入查询
发表于:2024-03-26 10:21:13浏览:304次
前言
本文将详细介绍fastadmin关联预载入查询,并提供整理的源码和通过示例代码进行说明。
后台模型中设置
在后台模型中设置关联预载入admin/model/User.php
public function user()
{
// setEagerlyType(0) JOIN查询
// setEagerlyType(1) IN查询
return $this->belongsTo(\app\admin\model\User::class,'user_id','id',[],'LEFT')->setEagerlyType(0);
}
后台控制器的方法中调用
方式一:在方法中单独调用(推荐)
buildparams(‘指定模糊查询的字段’,True关联查询 or False非关联查询)
list($where, $sort, $order, $offset, $limit) = $this->buildparams('card_no,title,user.phone',true);
方式二:在控制器中调用
// 查询字段
protected $searchFields = 'card_no,title,user.phone';
// 关联查询
protected $relationSearch = true;
栏目分类全部>