在Java中,我們有一批執行類似下面的Java代碼:Rails中是否有類似批量更新的內容?
Statement statement = null;
statement = connection.createStatement();
statement.addBatch("update people set firstname='John' where id=123");
statement.addBatch("update people set firstname='Eric' where id=456");
statement.addBatch("update people set firstname='May' where id=789");
int[] recordsAffected = statement.executeBatch();
如何做到在軌的ActiveRecord一樣嗎?
這就是你正在尋找http://api.rubyonrails.org/classes/ActiveRecord/Batches.html#method-i-find_in_batches? – 2015-02-24 11:24:56
例如我有表稱爲用戶,它有列點。我有這個值ID [1,2,3,9,10,15,20]相應的點[2,3,5,1,1,5,5]一次性更新數據庫中。像更新用戶設置點=(2,3,5,1,1,5,5)其中用戶id =(1,2,3,9,10,15,20),但這不是一個正確的SQL命令。 – Vijay 2015-02-24 11:33:42