How do I explicitly specify a Model's table-na

2019-01-03 23:50发布

I have a Model class called Countries and I want it to map to a DB table called 'cc'. How is that done in Rails (3)?

2条回答
来,给爷笑一个
2楼-- · 2019-01-04 00:04
class Countries < ActiveRecord::Base
    self.table_name = "cc"
end

In Rails 3.x this is the way to specify the table name.

查看更多
欢心
3楼-- · 2019-01-04 00:05

Rails >= 3.2 (including Rails 4+ and 5+):

class Countries < ActiveRecord::Base
  self.table_name = "cc"
end

Rails <= 3.1:

class Countries < ActiveRecord::Base
  self.set_table_name "cc"
  ...
end
查看更多
登录 后发表回答