How to override a column in Rails model?

前端 未结 4 436
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 09:31

I have a model for one of my database tables. I want to override the column name for that particular table. How would I achieve it.

For example, let my table be call

4条回答
  •  清歌不尽
    2020-12-14 10:02

    I'm a little late to the party here, but a really elegant way to do it is to simply use super

    class Dummy < ApplicationRecord
      def col_a
        super % 10 === 0 ? 0 : super
      end
    end
    

提交回复
热议问题