4

Configure the list of columns to update in upsert_all by jorgemanrubia · Pull Re...

 2 years ago
source link: https://github.com/rails/rails/pull/43470
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Copy link

Contributor

jorgemanrubia commented on Oct 15

edited

#41933 added a new on_duplicate: option to upsert_all, to allow providing custom SQL update code. This PR makes on_duplicate admit an array of columns too, so that upsert_all only updates those columns when a conflict happens.

Main motivation is limiting the list of updated columns in a database-agnostic way.

Pending:

  • Changelog update

CC @palkan @rafaelfranca

jorgemanrubia

force-pushed the configure-on-duplicate-columns

branch 3 times, most recently from 0780d29 to 7ae19ed last month

jorgemanrubia

changed the title Add support for passing a list of columns to update in upsert_all

Configure the list of columns to update in upsert_all

on Oct 15

jorgemanrubia

force-pushed the configure-on-duplicate-columns

branch 2 times, most recently from 9690640 to f3a59c2 last month

Copy link

Contributor

palkan commented on Oct 15

Main motivation is limiting the list of updated columns in a database-agnostic way.

I like it.

Though I'm not sure about the API, it seems a bit confusing: on_duplicate: %i[ name ]. It's not clear what this array means: are we checking duplicate names or what?

Maybe, something like on_duplicate: {update: %i[ name ]} or similar?

Copy link

Contributor

Author

jorgemanrubia commented on Oct 15

Thanks for weighting-in @palkan.

Maybe, something like on_duplicate: {update: %i[ name ]} or similar?

I agree it might be confusing, but I am not sure I prefer the hash form better.

Allowing raw strings or other types is what ActiveRecord does in other places. For example: Post.update_all 'name="foo"' or Post.update_all name: "foo", I think this approach is consistent with that. Although I agree it's not super-intuitive.

I also considered adding an additional option for this, but I think that would be more confusing, and we would need to make both options exclusive.

Said this, I am happy to explore other options here, it's just I am not super sold on the hash-form either sweat_smile.

jorgemanrubia

force-pushed the configure-on-duplicate-columns

branch 4 times, most recently from 0c62ce8 to 2f26549 last month

jorgemanrubia

force-pushed the configure-on-duplicate-columns

branch 2 times, most recently from 8740b40 to 04aa98b last month

jeremy

added this to the 7.0 milestone

22 days ago

Copy link

Member

@jeremy jeremy left a comment

Some minor docs + changelog comments

jorgemanrubia

force-pushed the configure-on-duplicate-columns

branch 6 times, most recently from 147d496 to 807bd24 2 days ago

jeremy

merged commit d133cc4 into

rails:main 2 days ago

4 checks passed

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

Assignees

No one assigned

Projects

None yet

Milestone

7.0

Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK