lets say I have a Array of Hashes like this
users_ar = [
{
id: 1,
name: 'Luke',
age: 19
},
{
id: 2,
name: 'Vader',
age: 44
},
{
id: 3,
name: 'Yoda',
age: 129
}
]
The id is their id in the User model.
How can i update all records at once in ruby on rails (if i don't need to validate the records) for performance reasons if i have thousands of records to update?
I'd like to find existing records by id and update name and age. Im looking for something like this:
users_to_update.update_all(users_ar)
My rails version is 5.2.3 and I'm using MySQL.
Thanks, Andreas
INSERT3 new rows instead ofUPDATE3 existing rows? Or, maybe, "upsert" wherein you either add new row(s) or modify existing row(s) based on some unique key (presumably theid).id? Orname?