Skip to content

Fix methods Hyperf\Database\Query\Builder::eachById bug and optimize code.#7671

Closed
gokure wants to merge 3 commits intohyperf:masterfrom
gokure:fix-each-by-id
Closed

Fix methods Hyperf\Database\Query\Builder::eachById bug and optimize code.#7671
gokure wants to merge 3 commits intohyperf:masterfrom
gokure:fix-each-by-id

Conversation

@gokure
Copy link
Contributor

@gokure gokure commented Dec 16, 2025

This PR fixes an issue with the method Query\Builder::eachById called by Db::table('artiles')->eachById(...).

  1. A TypeError occurred when the third ($column) argument was not provided.
  2. A TypeError because a Hyperf\Collection\Collection instance was passed.

Further changes:

  1. Delegate the logic of chunkById to orderedChunkById (to streamline functionality).
  2. Clean up the code by removing the duplicate methods Query\Builder\paginator and Query\Builder\simplePaginator which are identical to those in the BuildsQueirs trait.

use Hyperf\Database\Exception\MultipleRecordsFoundException;
use Hyperf\Database\Exception\RecordsNotFoundException;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 Collection 为啥要改?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用 Collection\Collection 代替 Model\Collection,使得 BuildsQueries Trait 更抽象了,其中的方法可以被 Query\Builder 和 Model\Builder 同时使用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来的 BuildsQueries 中混合使用了 Collection\Colleciton 和 Model\Collection,混乱易出错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants