修复CURD代码生成的关联报错
This commit is contained in:
@@ -301,7 +301,40 @@ trait Backend
|
|||||||
/**
|
/**
|
||||||
* 加载为 select(远程下拉选择框)数据,子类可覆盖
|
* 加载为 select(远程下拉选择框)数据,子类可覆盖
|
||||||
*/
|
*/
|
||||||
protected function _select(): void
|
protected function _select(): Response
|
||||||
{
|
{
|
||||||
|
if (empty($this->model)) {
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => [],
|
||||||
|
'total' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
|
||||||
|
// 远程下拉只要求包含主键与可显示字段;这里尽量返回主键 + quickSearch 字段,避免全量字段带来性能问题
|
||||||
|
$fields = [$pk];
|
||||||
|
$quickSearchArr = is_array($this->quickSearchField) ? $this->quickSearchField : explode(',', (string) $this->quickSearchField);
|
||||||
|
foreach ($quickSearchArr as $f) {
|
||||||
|
$f = trim((string) $f);
|
||||||
|
if ($f === '') continue;
|
||||||
|
$f = str_contains($f, '.') ? substr($f, strrpos($f, '.') + 1) : $f;
|
||||||
|
if ($f !== '' && !in_array($f, $fields, true)) {
|
||||||
|
$fields[] = $f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$res = $this->model
|
||||||
|
->field($fields)
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,9 +214,8 @@ class Backend extends Api
|
|||||||
public function select(WebmanRequest $request): Response
|
public function select(WebmanRequest $request): Response
|
||||||
{
|
{
|
||||||
$response = $this->initializeBackend($request);
|
$response = $this->initializeBackend($request);
|
||||||
if ($response !== null) return $response;
|
if ($response instanceof Response) return $response;
|
||||||
$this->_select();
|
return $this->_select();
|
||||||
return $this->success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user