簡體   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