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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:35:52+00:00 2026-06-12T01:35:52+00:00

Sorry for the basic, basic question but I’m having some trouble understanding the RoR

  • 0

Sorry for the basic, basic question but I’m having some trouble understanding the RoR doc.

say I have 3 models–Students, Classes, and Enrolled_in. If it isn’t clear, students will enroll in classes, so Enrolled_in should have Students and Classes as foreign keys. I generated the models for each of these, but I’m confused what I should put into the associated migration file vs. the associated model file for each table. Do I specify the columns of the table in the migration file, and the key constraints in models?

If someone could clarify this, or tell me how they would solve the example question I posted, that would be really helpful. Thanks.

  • 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-12T01:35:53+00:00Added an answer on June 12, 2026 at 1:35 am

    Firstly, to follow the convention the model name should be EnrolledIn, not Enrolled_in. Better yet, change it to Enrollment or something that has a definite meaning as a noun. And you’re also going to run into trouble trying to use Class (which is already a ruby object) as a model name. Perhaps change it to Course or something similar.

    That aside, you should define all columns in your migrations. You can define the enrolled_ins table like this:

    add_table :enrolled_ins do |t|
      t.references :student
      t.references :course        # I'm using course instead of class as noted above
    end
    

    The references shortcut will add a :student_id and :course_id as integer fields.

    In your model files you’ll have:

    # student.rb
    class Student < ActiveRecord::Base
      has_many :enrolled_ins
      has_many :courses, :through => :enrolled_ins
    end
    
    # course.rb
    class Course < ActiveRecord::Base
      has_many :enrolled_ins
      has_many :students, :through => :enrolled_ins
    end
    
    # enrolled_in.rb
    class EnrolledIn < ActiveRecord::Base
      belongs_to :student
      belongs_to :course
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the basic question, but I'm having trouble finding the right thing to
Sorry for asking a totally basic question, but if I have a synthesized property
Sorry for such a basic question regarding lists, but do we have this feature
Sorry for the probably basic question, but I'm trying to understand some code and
Sorry for a basic question. But, I need some help. In CSS, how can
Sorry basic question I'm sure but I can't seem to figure this out. Say
Sorry for asking probably a basic question, but I'm having a blackout. If I
sorry i know this is a basic question, but i have been trying for
Sorry if this is a basic question: I am having trouble doing form validation
I'm sorry for that basic question, but I'm in kinda trouble here... I've got

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.