I am using update_all to update a specific record directly on the database. I'm doing this in a script which parses a csv file. I know that update_all returns an integer on how many rows was changed. There are some rows where this returns 1 and some which returns 0 which means that no row was affected.
attrs = list of user attributes
User.update_all(attrs, { id: user.id })
Thanks in advance!
This usually happens when the database can't find a specific row which, in this case, is based on the user.id. I'm betting that you have a default_scope on user where that specific user is being filtered out. Try using User.unscoped.update_all(attrs, { id: user.id })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With