[13.x] insertOrIgnoreReturning with multiple unique keys#59187
Merged
taylorotwell merged 5 commits intolaravel:13.xfrom Mar 14, 2026
Merged
[13.x] insertOrIgnoreReturning with multiple unique keys#59187taylorotwell merged 5 commits intolaravel:13.xfrom
taylorotwell merged 5 commits intolaravel:13.xfrom
Conversation
Contributor
Author
|
Based on feedback by @antonkomarev I've also changed the The new method has now also been modified to be compatible with the // old:
public function saveOrIgnore(
array|string$uniqueBy,
array $options = [],
);
// new:
public function saveOrIgnore(
array $options = [],
array|string|null $uniqueBy = null,
);
// related:
save(array $options = [])So
|
Contributor
|
@tpetry thank you for your input! This feature will be much more flexible and useful for everybody. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #59025 added the
insertOrIgnoreReturningmethod which allows inserting data and ignoring duplicate conflicts with the great PostgreSQL/SQLite feature of, .e.g.,RETURNING *to get all inserted rows back.But that PR introduced a new concept, namely the
$uniqueByparam. The idea was, that you can limit the duplicate ignoring to specific unique columns/keys. But the problem is, you can only limit this logic to one unique key and you must use this feature. So theinsertOrIgnoreReturningmethod behaves differently compared toinsertOrIgnore:$uniqueByis not the one triggering the error.So after all, while
insertOrIgnoreReturningis a great new feature, the new behaviour made switching frominsertOrIgnorequite complicated - or impossible. I've discussed with @antonkomarev (the creator of PR #59025) on how to solve these issues by retaining the new$uniqueByfeature but making it optional for anyone as it is a niche feature.The method signature has been changed that it can be used absolutely identical to
insertOrIgnoreand users are able to opt-in gradually to more features:$returningto limit the columns returned$uniqueByto limit the duplicate detection to a specific unique key (or columns of a specific unique key)