Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 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'
- # Clear options records before destroy
- before_destroy :clear_options
- protected
- def clear_options
- options.clear
- end
- end
- model.options.clear
Add Comment
Please, Sign In to add comment