If I have a many to many relationship in Active Record, how do I add a new record?
Do I have to create a new instance of the join table and set the values or can I say something like
student.classes.add(class) and th开发者_开发问答at will work?
Sincerely, tesmar
No, it is not necessary to create a new instance of the join table. To add a new class you can simply use:
student.classes << class
student.save
精彩评论