title: How to set associations using namespaces and SQL tables with different names from those of Ruby on Rails models?
body: <p>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. </p>
  
  <hr>
  
  <p>For example...</p>
  
  <p>... in 'RAILS_ROOT/config/routes.rb' I have this:</p>
  
  <pre><code>namespace "users" do
    resources :accounts
  end
  
  namespace "second" do
    resources :profiles
  end
  </code></pre>
  
  <p>... in 'RAILS_ROOT/models/account.rb' I have this:</p>
  
  <pre><code>has_one :profile,
    :class_name =&gt; "Second::Profile"
  </code></pre>
  
  <p>... in 'RAILS_ROOT/models/profile.rb' I have this:</p>
  
  <pre><code>belongs_to :account
  </code></pre>
  
  <p>.. in the SQL database I have tables named:</p>
  
  <pre><code>accounts
  profiles  
  </code></pre>
  
  <hr>
  
  <p>I would like to continue to use the syntax</p>
  
  <pre><code>Users::Account.find(1)
  </code></pre>
  
  <p>in my RoR application, but I would like to have my SQL tables name like so:</p>
  
  <pre><code>users_accounts
  second_profiles
  </code></pre>
  
  <p><strong>How to do that?</strong></p>
  
  <p>P.S.: I read <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html" rel="nofollow">ActiveRecord::Base</a> "table_name()" and "table_name_prefix" sections but I am not able to set those.</p>