繁体   English   中英

Ruby on Rails — has_and_belongs_to_many关系

[英]Ruby on Rails — has_and_belongs_to_many relationship

我目前正在使用旧版数据库,并且有2个模型:提交和发布。

class Submission < ActiveRecord::Base
has_and_belongs_to_many :publications,  :join_table => "ish_sub_pub", :association_foreign_key => "SLN_PUB_FK"
end

class Publication < ActiveRecord::Base

has_and_belongs_to_many :submissions,  :join_table => "ish_sub_pub" ,
:association_foreign_key => "SLN_SUBMISSION_FK"

end

创建新提交时,我希望能够将发布与其关联,为此,我需要在联接表“ ish_sub_pub”中添加新记录。

对于如何继续将出版物添加到提交中,我有些困惑。

非常感谢你的帮助

假设您的发布已在my_publication实例化,那么您要做的就是just_created_submission << my_publication

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM