-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
public function testUpdateOrCreateWithNullId() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('You must provide attributes to check for duplicates'); |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
Tentative fix for #2945
Checklist