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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:29:16+00:00 2026-06-04T13:29:16+00:00

New to RoR, but am having a stab at building an app – and

  • 0

New to RoR, but am having a stab at building an app – and I’m looking for some advice on my db structure.

I’ve got 4 models/tables: Users > Clients > Jobs > Tasks

The app will work as follows:

  1. Users will login
  2. They can add Clients
  3. They can add Jobs to Clients
  4. They can add Tasks to Jobs

So, Tasks belong to Jobs, Jobs belong to Clients, and Clients belong to Users.

I want to query the DB for any one of a Client, a Job, or a Task and also make sure that it belongs to the currently logged-in User. I’m struggling to write a ‘railsy’ join query and design my associations so I can do this.

I know this would be super easy if I had a user_id field in every table, but that doesn’t seem like the right way to do it.

I’ve read the guide at http://guides.rubyonrails.org/association_basics.html, but am still in the dark a little. Can anyone shed some light on how I might structure my DB – and more importantly my associations?

Thx.

  • 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-04T13:29:17+00:00Added an answer on June 4, 2026 at 1:29 pm

    I’m not sure, if I understood your question correctly, but I believe this can be a solution:

    If you write your associations like this, ActiveRecord will create automatically the joins if you ask for user.jobs or user.tasks.

    class User < ActiveRecord::Base
      has_many :clients
      has_many :jobs, :through => :clients
      has_many :tasks, :through => :jobs
    end
    

    For more Information see the Rails-Api-Documentation

    If you want to get everything for a user in one request. You can do this:

    user.clients.joins(:jobs => :tasks)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read this , but I'm new to RoR so I'm having a little
This might seem a bit weird, but since I am new in RoR and
Very new to RoR and am working on a music app where a release
I'm kind of new to RoR so this may be a stupid question, but
Have written some RoR sites in the past, but never bothered too much at
I am new to RoR application and i want to install arachni but when
I'm new to RoR and having an issue when trying to save from multiple
I am pretty new to RoR and I am looking to deploy my next
I am completely new to ror and am following Michael Hartl's tutorial but I
I'm very new to ROR, and I'm having a problem making the elements in

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.