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

  • Home
  • SEARCH
  • 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 8096985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:36:54+00:00 2026-06-05T21:36:54+00:00

I currently have two different models: User and Project . The User model has

  • 0

I currently have two different models: User and Project. The User model has three types of users – owners, contractors and clients. I want to assign multiple contractors to one project. I am trying this with a has_many :through association, like so:

Class User
   has_many :assignments
   has_many :projects, :through => :assignments 

Class Project
   has_many :assignments
   has_many :contractors, :through => :assignments

Class Assignment
   belongs_to :user
   belongs_to :project

My issue is in using contractor_id in the assignments table instead of user_id.

In my assignments table I currently have columns contractor_id and project_id. Everything seems to work if I use user_id instead, but that will cause things to be pretty messy later on in my views.

How would I accomplish this?

  • 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-06-05T21:36:57+00:00Added an answer on June 5, 2026 at 9:36 pm

    You should use the :foreign_key option in Assignment, e.g.:

    class Assignment
      belongs_to :user, :foreign_key => :contractor_id
      belongs_to :project
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, users and themes, that I'm currently joining in a HABTM
Suppose you have two models, User and City, joined by a third model CityPermission:
struts 2.0.11 - Currently I'm in my local machine and have two different web
Currently I have Long Pres Gesture Recognizers on four different TableViews (two in each
I have two Model/Controllers which are essentially duplicating data (just on different pages). When
I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares. if suppose, Users table having 6 user
I have two models, Room and Image . Image is a generic model that
I have two sites running off the same base code. Each site has different
I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including
I currently have two panels within another large panel. The left panel is for

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.