Fastadmin报错Unknown column ‘xxx.deletetime‘ in ‘where clause
报错原因
在开启软删除后,设置了表别名,软删除字段依旧使用原表名。
解决方法
原代码
$list = $this->model->with(['admin', 'product'])->where($where)->order($sort, $order)->paginate($limit);foreach ($list as $row) {$row->getRelation('admin')->visible(['nickname']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
替换代码
$query = $this->model->with(['admin', 'product'])->where($where)->order($sort, $order)->group('supplier.id');
// 克隆查询对象避免影响后续操作
$countQuery = clone $query;
$listCount = $countQuery->count('supplier.id');
// 然后原来的查询继续执行获取数据
$list = $query->order($sort, $order)->limit($offset, $limit)->select();foreach ($list as $row) {$row->getRelation('admin')->visible(['nickname']);
}$result = array("total" => $listCount, "rows" => $list);