Topic: Basic Relationship Schema

Hello all,

I am very new to the Ruby on Rails scene -- my friend let me the Agile book. Anyways, I want to do my first [real] program, and do something.

There is going to be one side (maybe two if I want to incorporate it later) -- the student. The student will be able to do a few things:
-Register and Login
-Create a Class (if its not already taken)
-Join other people's Classes
-To view what classes other people are in, and see what classes they share with other people.

It's meant for those "weeks" before school when everyone asks what classes they have, etc. Get my drift?

I'm trying to figure out a basic schema on how I will start this and handle the databases, but i'm not sure how an experienced person would do it. Please help!

Thanks

Re: Basic Relationship Schema

This sounds like a fairly basic HABTM association (has and belongs to many). A student has many classes and a class has many students.

There's two ways to create this kind of relationship in Rails: has_and_belongs_to_many or has_many :through. See this picture for a nice example of the two.

The biggest difference between the two is if you want the join to have its own attributes. For example, if you wanted to keep track of the student's grade for a given class, or where they sit during that class, you would want the has_many :through association.

I can go into more detail if you need me to.

BTW, "Class" is a reserved word in Ruby, so you may want to call it Classroom, Period, or something.

Railscasts - Free Ruby on Rails Screencasts

Re: Basic Relationship Schema

Thanks for the feedback -- the relationship .png really helps! I'll get started on this, and i'll tell you how it's going!