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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:02:41+00:00 2026-05-27T13:02:41+00:00

I am making my first app in Ruby on Rails 3.1….Do I have these

  • 0

I am making my first app in Ruby on Rails 3.1….Do I have these relationships setup correctly? Essentially, a student/client will be able to login and rate a teacher. A client can have many teachers and a teacher can have many clients. Each client can create a rating for a particular teacher (a teacher can’t rate clients). Ratings are optional.

I intend to be able to display a teacher’s ratings from various clients and also allow clients to login and rate all the teachers they’ve had.

class Client < ActiveRecord::Base
  has_many :ratings
  has_and_belongs_to_many :teachers
end

class Teacher < ActiveRecord::Base
  has_many :ratings
  has_and_belongs_to_many :clients
end

class Rating < ActiveRecord::Base
  belongs_to :teacher
  belongs_to :client
end
  • 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-27T13:02:42+00:00Added an answer on May 27, 2026 at 1:02 pm

    I’d say that the usage of has_and_belongs_to_many should be used when you only have a database table and not a Rails model to join the models. In your case, since you do have a model called Rating then I’d say it is better to use has_many, :through.

    To accomplish that, change your Teacher and Client models to look like this:

    class Client < ActiveRecord::Base
      has_many :ratings
      has_many :teachers, :through => :ratings
    end
    
    class Teacher < ActiveRecord::Base
      has_many :ratings
      has_many :clients, :through => :ratings
    end
    

    The Rating model does not need any changing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making my first app which will use push notifications. I have decided
I am making good progress with my first Rails app with a lot of
I've been trying to setup my first rails app--I'm okay at stumbling around on
I'm new to Ruby on Rails, trying to get my first app working, which
I am making Ruby On Rails 3.0.3 app with JQuery 1.4.4 and jQuery UJS
I'm making a recipe-manager (who isn't as their first app?) in Rails, and here
Ok, I'm making my first ruby app. Who know moving everything over to 'production'
I will be making an iPhone app that will sell ebooks. we have a
New developer here. I'm making my first iPhone app. The app will display a
Making my first steps with NHibernate, I'm trying to have it creating my Tables

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.