如何在不保存(更新)基础对象的情况下仅保存(插入)关联的对象?ActiveRecord RoR - 仅保存新的关联对象
例如我只想保存电话号码,我不想重新保存/更新人物。
def create_numbers
#params => person_id => 41, person => {:phone_number => '12343445, 1234566, 234886'}
@person = params[:person_id]
nums = params[:person][:phone_numbers].split(',')
nums.each do |num|
@person.phone_numbers.build(:number => num)
end
@person.save #here I just want to save the numbers, I don't want to save the person. It has read only attributes
end
型号:
Person < ...
# id, name
belongs_to :school, :class_name => :facility
has_many :phone_numbers
end
PhoneNumber < ...
# id, number
belongs_to :person
end
这是一个有点哑例子,但它说明了什么,我试图完成