How to override a column in Rails model?

前端 未结 4 439
被撕碎了的回忆
被撕碎了的回忆 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:09

    You can achieve that by overwriting default accessors as described in the documentation. All column values are automatically available through basic accessors on the Active Record object, but sometimes you want to specialize this behavior. This can be done by overwriting the default accessors (using the same name as the attribute) and calling read_attribute(attr_name) and write_attribute(attr_name, value) to actually change things.

    Scroll to the Overwriting default accessors section for more info.

提交回复
热议问题