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 3873828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:04:55+00:00 2026-05-19T22:04:55+00:00

I have Worker, Manager, and Title models in Rails 2.x. There is also a

  • 0

I have Worker, Manager, and Title models in Rails 2.x. There is also a JOIN table that has only worker_id, manager_id, and title_id (no explicit model for this). Because of this JOIN table (and not having a model for it), I assume I have to have the following:

In the Worker model, I have:

Worker
has_and_belongs_to_many :managers
has_and_belongs_to_many :titles

But, in reality, the relationship is that Worker can only have 1 Manager, but many Titles. Also, many Workers have the same Manager.

Some sample data to illustrate the relationship:

Worker | Title | Manager
Tom    | A     | M1
Tom    | B     | M1
Bob    | A     | M2
Pam    | C     | M1

Is the above Worker model “correct”? When creating a new Worker (and all their relationships), I do:

worker = Worker.new("A")
title = "B"
manager = "C"
worker.titles << title
worker.managers << manager
worker.save

When I do this, I get the following in my database:

Worker | Title | Manager
A      | B     | null
A      | null  | C

I would like to get:

Worker | Title | Manager
A      | B     | C
  • 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-19T22:04:56+00:00Added an answer on May 19, 2026 at 10:04 pm

    You can move the manager_id (since, a Worker can have only on Manager) and have the relationships like this

    class Manager < AR::Base
      has_many :workers
    end
    

    Then, in the Worker belongs_to a Manager.

    class Worker < AR::Base
      belongs_to :manager
    end
    

    You need to have a join table, like “workers_titles” for hold the relationships between workers and titles

    create_table "workers_titles", :id => false do |t|
      t.column "worker_id", :integer, :null => false
      t.column "title_id",  :integer, :null => false
    end
    

    Models:

    class Worker < AR::Base
      has_and_belongs_to_many :titles
    end
    
    class Title < AR::Base
      has_and_belongs_to_many :workers
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic table that consists of worker names and manager names:
The main idea is that I have several worker instances of a Rails app,
Hopefully that title makes sense... Let's say I have an employee table: ID |
I have one app. that consists of Manager and Worker. Currently, the worker always
In my database I have a table Employee that has recursive association (an employee
I have a simple application with a manager thread that spawns ten simple worker
I have the following manager<->worker situation: class Manager { private: pthread_attr_t workerSettings; pthread_t worker;
I have a worker thread in a class that is owned by a ChildView.
I have a worker thread that may be active for short bursts of time
Sockets on Linux question I have a worker thread that is blocked on an

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.