Ask A Question


You’re not receiving notifications from this thread.

Incorrect setup for Model associations

Masud Hossain asked in Databases

I feel these associations are incorrectly set up. It's a bit similar to Trello, except I'm adding in a 'client' model too. The main part that's confusing to me is the fact user.rb, it's just bugging me.

What it's suppose to do:

  1. A user can create a business and belong to it as an employee.
  2. A business can have multiple employees (and a user belongs to that specific employee).
  3. A business can have multiple clients (and a user belongs to that specific client).

Is there a more efficient way to set this up?


@Tabish Iqbal,

do you mind showing me how the models would be set up? I don't seem to understand how the self joins would work in this case.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.