How to re-name a ActiveRecord Model which can automatically change the table name in DB?

后端 未结 4 1371
野趣味
野趣味 2021-02-04 05:21

I have a Active Record model \"car\", I would like to change the name of this model to \"train\" without changing functionalities inside, that\'s only

4条回答
  •  鱼传尺愫
    2021-02-04 05:48

    I would recommend the following:

    1. Change manually the Active Record model class into Train

    2. Make migration to change the database table name from cars to trains

    3. Make good search to change references from Car to Train.

    If you have constantly the need to change database table names, you might want to reconsider naming the tables more abstact way. Like in this case you could have table called vehicles and have the "type" field specifying the type (for instance: car or train).

提交回复
热议问题