开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜