Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.timestamps
end
end
end
class CreateCourses < ActiveRecord::Migration
def change
create_table :courses do |t|
t.string :name
t.timestamps
end
end
end
class CreateCourseTeachers < ActiveRecord::Migration
def change
create_table :course_teachers do |t|
t.integer :course_id
t.integer :teacher_id
t.timestamps
end
end
end
class CreateCourseStudents < ActiveRecord::Migration
def change
create_table :course_students do |t|
t.integer :course_id
t.integer :student_id
t.timestamps
end
end
end
class Course < ActiveRecord::Base
attr_accessible :name
has_many :course_students
has_many :students, :class_name => "User", :through => :course_students
has_many :course_teachers
has_many :teachers, :class_name => "User", :through => :course_teachers
end
class CourseStudent < ActiveRecord::Base
belongs_to :course
belongs_to :student, :class_name => "User"
end
class CourseTeacher < ActiveRecord::Base
belongs_to :course
belongs_to :teacher, :class_name => "User"
end
class User < ActiveRecord::Base
attr_accessible :name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.