rails 如何规划高考 app 的模型关系
How to plan a model relation for collage admission app in rails
我想要一个基本的学生注册和登录设施。
登录后,学生应被引导至注册表,其中包含学生联系方式和学生分数的表格。
学生联系方式表包含
student contact form
first name
last name
address
mobile no
gender
fathers name
fathers occupation
mothers name.
学生成绩单包含
**registration form**
.
|-- Board of examination
| `-- Branches(ex:science,:humanities)
| `--science[when i choose science]
`--science subject1
`--science subject2
`--common paper for sciecnce and humanities
| `--humanities[when is choose humanities]
`--humanities subject1
`--humanities subject2
`--common paper for sciecnce and humanities
想想数据之间的关系。您从 Examination Board 开始的树提供了一些线索。一位用户将拥有多个主题和多个标记。用户、主题和标记如何关联?一种可能
class User
has_many :subject_marks
has_many :subjects, through: subject_marks
end
class Subject
belongs_to :branch
has_many :subject_marks
has_many :users, through: subject_marks
end
class SubjectMark
belongs_to :user
belongs_to :subject
end
class Branch
has_many :subjects
belongs_to :examination_board
end
class ExaminationBoard
has_many :branches
end
我想要一个基本的学生注册和登录设施。
登录后,学生应被引导至注册表,其中包含学生联系方式和学生分数的表格。
学生联系方式表包含
student contact form
first name
last name
address
mobile no
gender
fathers name
fathers occupation
mothers name.
学生成绩单包含
**registration form**
.
|-- Board of examination
| `-- Branches(ex:science,:humanities)
| `--science[when i choose science]
`--science subject1
`--science subject2
`--common paper for sciecnce and humanities
| `--humanities[when is choose humanities]
`--humanities subject1
`--humanities subject2
`--common paper for sciecnce and humanities
想想数据之间的关系。您从 Examination Board 开始的树提供了一些线索。一位用户将拥有多个主题和多个标记。用户、主题和标记如何关联?一种可能
class User
has_many :subject_marks
has_many :subjects, through: subject_marks
end
class Subject
belongs_to :branch
has_many :subject_marks
has_many :users, through: subject_marks
end
class SubjectMark
belongs_to :user
belongs_to :subject
end
class Branch
has_many :subjects
belongs_to :examination_board
end
class ExaminationBoard
has_many :branches
end