案子:
表:
teacher :id :name
course :id :name
teachercourse :id :teacher_id :course_id
如何使用导轨对这 3 个表进行内部连接?
编辑(我的模型):
class Course < ActiveRecord::Base
attr_accessible :name
has_many :teachercourses
has_many :teachers, through: :teachercourse
end
class Teacher < ActiveRecord::Base
attr_accessible :name
has_many :teachercourses
has_many :courses, through: :teachercourse
end
class Teachercourse < ActiveRecord::Base
attr_accessible :course_id, :teacher_id
belongs_to :course
belongs_to :teacher
end
Edit2 - 我需要加入结果(显示操作):
class CourseController < ApplicationController
def show
#not real syntax
@course=Course.find(join:teacher,teachercourse,teacher :: where course='javacourse');
end
end