Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

orm 多库链接的情况无法在模型中通过$connection指定连接

Open
#105 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
mysql, php
Domain
databases

Research direction

Start at the selectInput(Request $request) method shown in the issue and trace how the model and database connection are selected before the table description query runs. Verify the multi-database case where a model specifies $connection, and consider the issue complete when the query uses that connection instead of assuming the mysql configuration.

Written by the indexing model from the issue text.

Description

orm 多库链接的情况无法在模型中通过$connection指定连接
指定第二个库时,查询列表会报错 说第一个库不存在某表
排查到原因是
` protected function selectInput(Request $request): array
{
$field = $request->get('field');
$order = $request->get('order', 'asc');
$format = $request->get('format', 'normal');
$limit = (int)$request->get('limit', $format === 'tree' ? 1000 : 10);
$limit = $limit <= 0 ? 10 : $limit;
$order = $order === 'asc' ? 'asc' : 'desc';
$where = $request->get();
$page = (int)$request->get('page');
$page = $page > 0 ? $page : 1;
$table = config('plugin.admin.database.connections.mysql.prefix') . $this->model->getTable();

    $allow_column = Util::db()->select("desc `$table`");
    if (!$allow_column) {
        throw new BusinessException('表不存在');
    }
    $allow_column = array_column($allow_column, 'Field', 'Field');
    if (!in_array($field, $allow_column)) {
        $field = null;
    }
    foreach ($where as $column => $value) {
        if (
            $value === '' || !isset($allow_column[$column]) ||
            is_array($value) && (empty($value) || !in_array($value[0], ['null', 'not null']) && !isset($value[1]))
        ) {
            unset($where[$column]);
        }
    }
    // 按照数据限制字段返回数据
    if (!Auth::isSuperAdmin()) {
        if ($this->dataLimit === 'personal') {
            $where[$this->dataLimitField] = admin_id();
        } elseif ($this->dataLimit === 'auth') {
            $primary_key = $this->model->getKeyName();
            if (!Auth::isSuperAdmin() && (!isset($where[$primary_key]) || $this->dataLimitField != $primary_key)) {
                $where[$this->dataLimitField] = ['in', Auth::getScopeAdminIds(true)];
            }
        }
    }
    return [$where, $format, $limit, $field, $order, $page];
}`

中config('plugin.admin.database.connections.mysql.prefix') 写死了这个mysql

Dominant language
JavaScript
Stars
378
Forks
48
Avg merge
20h 9m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from webman-php/admin

All issues in webman-php/admin

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.