Configure the list of columns to update in upsert_all by jorgemanrubia · Pull Re...
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.
Conversation
#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
force-pushed the configure-on-duplicate-columns
branch
3 times, most recently
from
0780d29
to
7ae19ed
last month
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
force-pushed the configure-on-duplicate-columns
branch
2 times, most recently
from
9690640
to
f3a59c2
last month
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?
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 .
force-pushed the configure-on-duplicate-columns
branch
4 times, most recently
from
0c62ce8
to
2f26549
last month
force-pushed the configure-on-duplicate-columns
branch
2 times, most recently
from
8740b40
to
04aa98b
last month
Some minor docs + changelog comments
force-pushed the configure-on-duplicate-columns
branch
6 times, most recently
from
147d496
to
807bd24
2 days ago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No one assigned
None yet
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK