Reputation:
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!
Upvotes: 3
Views: 1728
Reputation: 29599
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 })
Upvotes: 6