I am using Ruby on Rails 3 and a SQL database. I'm trying to rename database tables in order to reach "harmony of names" between RoR Models and SQL tables.
For example...
... in 'RAILS_ROOT/config/routes.rb' I have this:
namespace "users" do
  resources :accounts
end
namespace "second" do
  resources :profiles
end
... in 'RAILS_ROOT/models/account.rb' I have this:
has_one :profile,
  :class_name => "Second::Profile"
... in 'RAILS_ROOT/models/profile.rb' I have this:
belongs_to :accou开发者_StackOverflow中文版nt
.. in the SQL database I have tables named:
accounts
profiles  
I would like to continue to use the syntax
Users::Account.find(1)
in my RoR application, but I would like to have my SQL tables name like so:
users_accounts
second_profiles
How to do that?
P.S.: I read ActiveRecord::Base "table_name()" and "table_name_prefix" sections but I am not able to set those.
Use the following code in your models:
class User
  set_table_name "users_accounts"
end
class Profile
  set_table_name "second_profiles"
end
I hope it helps.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论