有些地方我没有理解...
我的模型中有这个内容:
class Model < ActiveRecord::Base
has_many :model_options # a link table for many to many
has_many :options,
:through => :model_options,
:dependent => :destroy,
:foreign_key => 'model_id'
end
我尝试做到这一点:
model = Model.find(id)
model.options.delete # also tried model.options.delete_all
但这并没有从数据库中删除记录。 相反,我必须执行以下操作:
model.options.each do |option|
option.delete
end
...这不可能是最好的方法。
那么,请问什么是最好的方法?