数据库查询事件问题,是否应该获取监听最后一次结果才对,而不是数组

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

Nobody has claimed this yet.

Assessment

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

Research direction

Start at the shown select(BaseQuery) method and trace db->trigger('before_select', $query) to confirm whether it returns an array of listener results or the final result. Verify the fallback query path and define done as correctly using the final listener result when present, while preserving normal query execution when no listener handles the event.

Written by the indexing model from the issue text.

Description

$resultSet返回的是一个数组永远也进入不了if语句,应修改为只获取最后一次结果

/**
     * 查找记录
     * @access public
     * @param BaseQuery $query 查询对象
     * @return array
     * @throws DbException
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     */
    public function select(BaseQuery $query): array
    {

        $resultSet = $this->db->trigger('before_select', $query);

        //$resultSet返回的是一个数组永远也进入不了if

        //应修改为,只获取最后一次结果
        $resultSet = $this->db->trigger('before_select', $query,true);

        if (!$resultSet) {

            // 执行查询操作
            $resultSet = $this->query($query, function ($query) {
                return $this->builder->select($query);
            });
        }

        return $resultSet;
    }
Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

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 top-think/think-orm

All issues in top-think/think-orm

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.