Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset _id: null to let it be autogenerated #2969

Merged
merged 3 commits into from
May 28, 2024
Merged

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 22, 2024

Tentative fix for #2945

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

src/Eloquent/Builder.php Outdated Show resolved Hide resolved
public function testUpdateOrCreateWithNullId()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You must provide attributes to check for duplicates');
Copy link
Member

Choose a reason for hiding this comment

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

Noted that expectExceptionMessage() is a substring match.

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You must provide attributes to check for duplicates');
User::updateOrCreate(
['_id' => null],
Copy link
Member

Choose a reason for hiding this comment

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

Do users typically pass an explicit null value to this method, or would this argument come from another source such as an empty model object?

Copy link
Member Author

Choose a reason for hiding this comment

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

From the original issue, null is a fallback value.

$id = $request->get('id') ?? null;
Model::updateOrCreate(['_id' => $id], $data);

@GromNaN GromNaN marked this pull request as ready for review May 28, 2024 13:13
@GromNaN GromNaN requested a review from a team as a code owner May 28, 2024 13:13
@GromNaN GromNaN requested review from alcaeus and jmikola May 28, 2024 13:13
@GromNaN GromNaN enabled auto-merge (squash) May 28, 2024 14:03
@GromNaN GromNaN merged commit 3f84373 into mongodb:4.4 May 28, 2024
26 checks passed
@GromNaN GromNaN added this to the 4.4 milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants