-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Adds a
createOrFirst
method to Eloquent (#47973)
* Adds more services to the docker-compose.yml for ease local testing * Adds createOrFirst method to the query builder * Adds createOrFirst to the BelongsToMany relation * Adds createOrFirst to HasOneOrMany relation * Test createOrFirst using with casts * Test createOrFirst with enum casting * Test createOrFirst with SoftDeletes models * Adds test for the DatabaseElqouentHasManyTest suite * Adds createOrRestore scope to soft-deleting models * Adds tests for the Morph relation * Adds docblocks * Adds more context to comments * Tweaks comments * Move integration tests to the correct namespace * Remove unnecessary imports * Replace inline patterns with private constants * Switch to static properties instead of constants since 8.1 doesnt allow constants on traits * Introduce a new UniqueConstraintViolationException that is a sub-type of QueryException * Use create method instead of newModelInstance+save * Use the createOrFirst inside the firstOrCreate method to avoid race condition in the latter * Fix StyleCI * Fix tests using mocks that throw the QueryException instead of the newly added UniqueConstraintViolationException * Return false by default in the base implementation of unique detection * Tweaks the comment * Use the create method in the createOrFirst one * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
c658d14
commit 14e8ee4
Showing
23 changed files
with
727 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Illuminate/Database/UniqueConstraintViolationException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database; | ||
|
||
class UniqueConstraintViolationException extends QueryException | ||
{ | ||
} |
Oops, something went wrong.