Skip to content

Instantly share code, notes, and snippets.

@ifyouseewendy
Created April 8, 2012 11:02
Show Gist options
  • Save ifyouseewendy/2336637 to your computer and use it in GitHub Desktop.
Save ifyouseewendy/2336637 to your computer and use it in GitHub Desktop.
campus note
Note 1.
Single Table Inheritance
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
class Teacher < User
has_many :courses
end
class Course
belongs_to :teacher
has_and_belongs_to_many :students
end
class Student < User
has_and_belongs_to_many :courses
end
Table Structure
<1. users, should have a type column to trigger single-table inheritance.
<2. courses, for Teacher and Course, 1 to many, :foreign_key => teacher_id
<3. courses_students, for Course and Student, many to many, :foreign_key => student_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment