我将开发一个大学管理项目,其中包括一些限制,
我该如何设计?
答案 0 :(得分:0)
模型是这样的:
class Semester < ActiveRecord::Base
has_many :subjects
has_many :semester_students
has_many :students, :through => :semester_students
end
class Subject < ActiveRecord::Base
belongs_to :semester
end
class Student < ActiveRecord::Base
has_many :semester_students
has_many :semesters, :through => :semester_students
end
使用外键(semester_id,student_id,subject_id等)和关联表(semester_students)来实现一对一,一对多和多对多关系。