active_record_upsert icon indicating copy to clipboard operation
active_record_upsert copied to clipboard

Upsert allowing keys to be excluded

Open andrewclink opened this issue 5 years ago • 3 comments

This PR adds exclude: to upsert_options to allow one to leave certain attributes alone during an upsert. The use case is when a column is defined as NOT NULL DEFAULT "something" and an attempt to insert NULL into that column is unwanted.

This includes minimal passing tests.

Ruby 2.3+ is required due to the safe navigation operator being used once. If that's undesirable, an explicit check for nil could be used instead.

andrewclink avatar Jan 27 '20 23:01 andrewclink

This fixes #102

andrewclink avatar Jan 27 '20 23:01 andrewclink

Regarding the 2.3, the CI only tests 2.4+. We should be good there.

olleolleolle avatar Jan 28 '20 10:01 olleolleolle

@andrewclink Can you rebase your branch on the target branch?

jesjos avatar Nov 19 '22 15:11 jesjos