我有一个像这样的协会:
class Contact < ActiveRecord::Base
has_many :contact_classifications
has_many :classifications, through: :contact_classifications
end
class ContactClassification < ActiveRecord::Base
belongs_to :contact
belongs_to :classification
end
class Classification < ActiveRecord::Base
has_many :contact_classifications
has_many :contacts, through: :contact_classifications
end
我有现有联系人和现有分类。当我使用以下代码时:
contact = Contact.find(id)
classification = Classification.find(1)
contact.classifications << classification
它将记录插入到联接表ContactClassification中。我想在两个现有记录之间建立关联,而不创建连接记录,直到在其中一个记录上调用save之后。
我怎样才能做到这一点?