开发者

Syntax to Access Multiword Database Tables in Ruby on Rails

I have a table called User_开发者_Go百科Roles in my sqlite3 database. Using the Ruby on Rails console I've tried the following:

  • UserRoles.first
  • User_Roles.first
  • userroles.first
  • User_Role.first
  • user_roles.first
  • UserRole.first
  • User_Role.first
  • userrole.first

What am I typing incorrect just to get the first row in the User_Roles table?

Thanks


I would guess UserRole.first

It should be whatever the name of the corresponding model class is. It's odd that the table name is capitalized. Normally, this is what you'd expect, having generated the migration using something like rails generate model UserRole:

table name: user_roles model file: app/models/user_role.rb model name: UserRole (defined in user_role.rb)

If the naming of all of these things doesn't jive together, then strange (or more likely just wrong) things may happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜