Skip to content
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

Fix upserting for custom :on_duplicate and :unique_by consisting of all inserts keys #49870

Conversation

fatkodima
Copy link
Member

Fixes #49867.

Before, when @on_duplicate = :skip if @on_duplicate == :update && updatable_columns.empty? line run, it incorrectly ignores the fact that custom :on_duplicate was passed and @on_duplicate is already configured in the configure_on_duplicate_update_logic method. So I moved that logic into that method.

@fatkodima fatkodima force-pushed the fix-upsert-custom_on_duplicate-and-unique_by branch from 9c29602 to 3bf867d Compare October 31, 2023 17:19
@jonathanhefner jonathanhefner merged commit f7bc844 into rails:main Oct 31, 2023
4 checks passed
@jonathanhefner
Copy link
Member

jonathanhefner commented Oct 31, 2023

Thank you, @fatkodima! 🆙

Backported to 7-1-stable in 28a4d5f and 7-0-stable in edcde0d.

jonathanhefner added a commit that referenced this pull request Oct 31, 2023
…te-and-unique_by

Fix upserting for custom `:on_duplicate` and `:unique_by` consisting of all inserts keys

(cherry picked from commit f7bc844)
jonathanhefner added a commit that referenced this pull request Oct 31, 2023
…te-and-unique_by

Fix upserting for custom `:on_duplicate` and `:unique_by` consisting of all inserts keys

(cherry picked from commit f7bc844)
@fatkodima fatkodima deleted the fix-upsert-custom_on_duplicate-and-unique_by branch November 1, 2023 00:12
@javierav
Copy link
Contributor

javierav commented Nov 1, 2023

Thank you @fatkodima and @jonathanhefner for the quick solution! 👏🏻 👏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ActiveRecord] Upsert ignore on_duplicate if unique_by is specified
4 participants