Created
April 8, 2012 11:02
-
-
Save ifyouseewendy/2336637 to your computer and use it in GitHub Desktop.
campus note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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