-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.1] Add Model::saveOrFail() to execute save operation within database transaction. #11202
Conversation
$saved = false; | ||
|
||
$this->getConnection()->transaction(function () { | ||
$saved = $this->save($options); |
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.
this function will not modify the saved variable - php puts it in a different scope
Needs tests because the current implementation doesn't actually work. |
…se transaction. Signed-off-by: crynobone <[email protected]>
06fcda3
to
3496a5a
Compare
$user = EloquentTestUser::first(); | ||
$this->assertEquals('[email protected]', $user->email); | ||
$this->assertEquals(1, $user->id); | ||
}); |
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.
This tests follow testNestedTransactions()
with the only different with using saveOrFail()
.
Duplicate |
$db->rollBack(); | ||
|
||
throw $e; | ||
} catch (Throwable $e) { |
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.
no need for all this, just use finally
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.
oh, wait, ignore me - we don't want to always rollback, lol
Signed-off-by: crynobone <[email protected]>
0da75d2
to
777efcd
Compare
This would simplify the following operation:
to
Signed-off-by: crynobone [email protected]