轨道3 + ActiveRecord的,到&QUOT的最佳方式;大规模更新"为所有符合条件的记录单场 [英] Rails 3 + activerecord, the best way to "mass update" a single field for all the records that meet a condition

查看:83
本文介绍了轨道3 + ActiveRecord的,到&QUOT的最佳方式;大规模更新"为所有符合条件的记录单场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在轨道3,使用ActiveRecord的,有没有一个单一的查询方法来设置:隐藏字段为 TRUE 作为所有符合条件的记录...发言权例如,:条件=> [PHONENUM =?,some_phone_number]

In rails 3, using activerecord, is there a single-query way to set the :hidden field to TRUE for all records that meet a condition ... say, for example, :condition => [ "phonenum = ?", some_phone_number ]

如果一个查询不能做到这一点,什么是最佳的方法呢?

If a single query cannot do it, what IS the optimal approach?

推荐答案

使用 update_all

.update_all( {:hidden => true}, {:phonenum => some_phone_number} )

这篇关于轨道3 + ActiveRecord的,到&QUOT的最佳方式;大规模更新"为所有符合条件的记录单场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆