2

深入研究文档和 api,我似乎错过了如何一次更新多行中的一个字段。

就像是

Table.select(:field).update("update to this").where(id: 4,5,6)

会好的。

这样的事情存在吗?这比必须将所有内容存储在数组中,将其设置为一个值并save每次调用要好得多。

4

1 回答 1

5

您可以使用update_all方法,例如:

Table.update_all("field = 'update to this'", ["id in (?)", ids])
于 2012-12-10T01:06:08.287 回答