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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:11:57+00:00 2026-05-11T16:11:57+00:00

I have a tree-like structure to my database in an app I am writing

  • 0

I have a “tree-like” structure to my database in an app I am writing so that:

training has_many class_times 

and

class_time has_many reservations

Is there a way to look up all reservations under a a given training? I could iterate through all of class times/add a foreign key, of course, but for some reason I have this little voice in the back of my head that says I might not need a foreign key for 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-05-11T16:11:57+00:00Added an answer on May 11, 2026 at 4:11 pm
    class Training < ActiveRecord::Base
      has_many :class_times
      has_many :reservations, :through => :class_times
    end
    
    class ClassTime < ActiveRecord::Base
      has_many :reservations
    end
    

    then you can do:

    training = Training.find(:first)
    training.reservations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree structure in memory that I would like to render in
In C# I have an intrusive tree structure that looks like this: public abstract
I have an object tree that looks something like Ball / \ LegalBall IllegalBall
I have a tree data structure that is L levels deep each node has
I have a tree structure that can be n-levels deep, without restriction. That means
I have a tree-style database with the following structure: Table fields: NodeID int ParentID
I have a tree-like structure of abstract classes and case classes representing an Abstract
I have a tree like structure roughly like this: class Node < ActiveRecord::Base belongs_to
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have a tree that consists of several objects, where each object has a

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.