简体   繁体   中英

Ruby on Rails table names: what's permitted?

I need to build a Ruby on Rails database which can handle multiple “modules” which provide various related sets of functionality. I'd like some way of grouping the module tables by their modules, almost akin to namespaces.

Is the : character safe for use in table names with Ruby on Rails, and if not, what's a good alternative?

That really depends on the database provider. If you're using mysql or some other sql based database, I'd say that: isn't permitted, but what you can do is modify the migration file to name the table something like modulename_modelname. Then in the model itself you can specify the table name by calling set_table_name as documented here:

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-set_table_name

That just looks dangerous and ugly to me. I'd stick with prepending something with underscores.

admin_users
admin_tools
supervisor_charts

etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM