Skip to content

Conversation

@zds-s
Copy link
Contributor

@zds-s zds-s commented Aug 6, 2025

example

user_table:

| id | username |
|----|----------|
| 1  | except1  |
| 2  | except2  |
| 3  | except3  |
| 4  | success  |

code:

public function handle(): void
{
    $users = User::query()->whereIn('id', [1, 2, 3])->get();
    $normalUsers = User::query()->except($users)->get(['id', 'username']);
    dump($normalUsers->toArray());
}

output:

array:1 [
  0 => array:2 [
    "id" => 4
    "username" => "success"
  ]
]

zds-s and others added 5 commits August 6, 2025 11:41
- Added testExceptMethodWithModel() to test excluding a single model
- Added testExceptMethodWithCollectionOfModel() to test excluding a collection of models
- Added testExceptMethodWithArrayOfModel() to test excluding an array of models
- Tests verify proper method forwarding from Model Builder to Query Builder
- Tests ensure correct return values for method chaining
- Minor code formatting improvements in Query Builder

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fix: Move to Model/Builder and modify the test
@huangdijia huangdijia requested a review from Copilot August 7, 2025 08:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an except method to the Hyperf Database Model Builder that allows excluding specific models from query results. The method provides a convenient way to filter out models by their primary keys.

  • Added except method to Model\Builder class that accepts a single model or iterable of models
  • Added comprehensive test coverage for the new method with different input types
  • The implementation uses existing whereKeyNot method internally for consistency

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/database/src/Model/Builder.php Implements the new except method that excludes models from query results
src/database/tests/ModelBuilderTest.php Adds three test methods covering single model, collection, and array usage scenarios

@limingxinleo limingxinleo changed the title Added except method to Hyperf\Database\Query\Builder Added method Hyperf\Database\Model\Builder::except(). Aug 26, 2025
@limingxinleo limingxinleo merged commit 2ec942f into hyperf:master Aug 26, 2025
71 checks passed
@zds-s zds-s deleted the feature/add-except-method branch August 26, 2025 02:56
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.

3 participants