Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
因此,用户可以是学生或家长。要定义这种关系,用户可以是家长,但不能是学生,一个家长有很多学生。
这是该关系的 ERD。
我将如何在 Rails 4 中创建这种关系?
我认为这应该有效
class User has_many :parents, through: 'students_parents' has_many :students, through: 'students_parents' class StudentParent belongs_to :student, class_name: 'User' belongs_to :parent, class_name: 'User'