简体   繁体   中英

Ruby on Rails — has_and_belongs_to_many relationship

I am currently using a legacy database and I have 2 models: submission and publication.

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

When i create a new submission, i want to be able to associate a publication to it and for this i will need to add a new record in the join table, 'ish_sub_pub'.

I am a bit confused about how to proceed with adding a publication to a submission.

Thanks a lot for your help

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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