-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Unset _id: null
to let it be autogenerated
#2969
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1151,4 +1151,21 @@ public function testUpdateOrCreate(array $criteria) | |
$this->assertEquals($createdAt, $checkUser->created_at->getTimestamp()); | ||
$this->assertEquals($updatedAt, $checkUser->updated_at->getTimestamp()); | ||
} | ||
|
||
public function testCreateWithNullId() | ||
{ | ||
$user = User::create(['_id' => null, 'email' => 'foo@bar']); | ||
$this->assertNotNull(ObjectId::class, $user->id); | ||
$this->assertSame(1, User::count()); | ||
} | ||
|
||
public function testUpdateOrCreateWithNullId() | ||
{ | ||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. Do users typically pass an explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the original issue, $id = $request->get('id') ?? null;
Model::updateOrCreate(['_id' => $id], $data); |
||
['email' => 'jane.doe@example.com'], | ||
); | ||
} | ||
} |
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.