I am using the Sequel gem to bulk update Users in MySql.
users = Users.filter(:id => ids).all
raise if users.nil?
updated_users = Users.filter(:id => addon_ids).update({deleted: 1, moderator_id: moderator_id})
p updated_users
# => 3
According to Sequel documentation,
"update [and delete] should return the number of rows affected..."
So the behavior above is expected, but my question is, how can I get the Sequel gem to return the updated records instead of the number of affected records?
I am expecting this behavior:
users = Users.filter(:id => ids).all
raise if users.nil?
updated_users = Users.filter(:id => addon_ids).update({deleted: 1, moderator_id: moderator_id})
p updated_users
# => [#<Users @values={:id=>1, :moderator_id=>"testuser", :deleted=>1}>, #<Users @values={:id=>2, :moderator_id=>"testuser", :deleted=>1}>, #<Users @values={:id=>3, :moderator_id=>"testuser", :deleted=>1}>]
Well, this is what DBs return so Sequel does what the developer expects it to do. Instead do this:
This way you don't assign the number of affected rows to
updated_users.