Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 381649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:06:21+00:00 2026-05-12T15:06:21+00:00

This is a separate question, but it is related to an earlier question: Three

  • 0

This is a separate question, but it is related to an earlier question: Three Column Join in Rails with Active Scaffold. To sum up: Rails automatically looks for a two column join table, but it doesn’t do the same for a three column join table. I’ve tried the suggestions in the previous question, but it comes down to this:

If you have the models Project, Employee, Role and each has a habtm relationship to the other two, rails will do each relationship separately but not as a whole.

class Employee < ActiveRecord::Base
    #has_many        :employees_projects_roles
    #has_many        :roles,     :through => :employees_projects_roles
    #has_many        :projects,  :through => :employees_projects_roles
     has_and_belongs_to_many :roles
     has_and_belongs_to_many :projects
end

repeated for Project, Role follows

class Role < ActiveRecord::Base
    #has_many :employees, :through => :employees_projects_roles
    #has_many :projects,  :through => :employees_projects_roles
    has_and_belongs_to_many :employees
    has_and_belongs_to_many :projects
end

My question is this, since rails looks for employees_projects, projects_roles, and employees_roles but not employees_projects_roles is there a way to alias those names to the real table name and still allow CRUD functionality in the database (MySQL or PostgreSQL)?

[Edit]
Whoops. I have got to stop answering and questioning publicly before I’ve had enough coffee. Changed the commented out portion from hmt to habtm. Included commented out portion of code to reflect the various options I’ve tried.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:06:22+00:00Added an answer on May 12, 2026 at 3:06 pm

    I’m assuming that you have something like this joining your models together:

      def self.up
        create_table :my_join_table, :id => false do |t|
          t.integer :employee_id
          t.integer :role_id
          t.integer :project_id
          t.timestamps
        end
      end
    

    If so you, simply need to specify the name of the join table to use with your habtm.

    class Employee < ActiveRecord::Base
      has_and_belongs_to_many :roles, :join_table => "my_join_table"
      has_and_belongs_to_many :projects, :join_table => "my_join_table"
    end
    
    class Project < ActiveRecord::Base
      has_and_belongs_to_many :roles, :join_table => "my_join_table"
      has_and_belongs_to_many :employees, :join_table => "my_join_table"
    end
    
    class Role < ActiveRecord::Base
      has_and_belongs_to_many :employees, :join_table => "my_join_table"
      has_and_belongs_to_many :projects, :join_table => "my_join_table"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is very much related to: A) How to separate CUDA code into
This question is related to UITableView issue when using separate delegate/dataSource , though I
This question is related to C#, but may be applicable to other languages as
I know there are many queries related to this question but my problem is
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Partially related to an earlier question of mine , I have a system in
I apologize in advance for the rambling nature of this question, but I have
This question is related to following thread. Prism RegionAdapter - Removing then Adding View
I realize that this question is slightly server related and could be posted on
I have seen this question and a number of blog posts related to using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.