我正在使用Sequel gem 批量更新 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
根据Sequel 文档,
“更新 [和删除] 应该返回受影响的行数......”
所以上面的行为是预期的,但我的问题是,我怎样才能让 Sequel gem 返回更新的记录而不是受影响的记录数?
我期待这种行为:
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}>]