update_all with a method

后端 未结 3 1862
甜味超标
甜味超标 2021-01-21 04:18

Lets say I have a model:

class Result < ActiveRecord::Base
  attr_accessible :x, :y, :sum
end

Inste

3条回答
  •  一个人的身影
    2021-01-21 05:04

    I'm completely beginner, just wondering Why not add a self block like below, without adding separate column in db, you still can access Sum.sum from outside.

    def self.sum 
    x+y 
    end
    

提交回复
热议问题