瀏覽代碼

Rails: skip validation on updates (#2616)

Also, only select the fields required.
Nate Berkopec 8 年之前
父節點
當前提交
97a34a74f4
共有 1 個文件被更改,包括 2 次插入3 次删除
  1. 2 3
      frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

+ 2 - 3
frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

@@ -37,9 +37,8 @@ class HelloWorldController < ApplicationController
     worlds = (1..queries).map do
       # get a random row from the database, which we know has 10000
       # rows with ids 1 - 10000
-      world = World.find(Random.rand(10000) + 1)
-      world.randomNumber = Random.rand(10000) + 1
-      World.update(world.id, :randomNumber => world.randomNumber)
+      world = World.select(:randomNumber).find(Random.rand(10000) + 1)
+      world.update_attribute(:randomNumber => Random.rand(10000) + 1)
       world
     end