Skip to content

Instantly share code, notes, and snippets.

@sferik
Created June 11, 2013 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/5754135 to your computer and use it in GitHub Desktop.
Save sferik/5754135 to your computer and use it in GitHub Desktop.
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