ReinH (owner)

Revisions

gist: 221655 Download_button fork
public
Public Clone URL: git://gist.github.com/221655.git
Embed All Files: show embed
has_many_through_dependent.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
class ActiveRecord::Associations::HasManyThroughAssociation
  private
  def delete_records(records)
    klass = @reflection.through_reflection.klass
    method_map = {:destroy => :destroy_all}
    method_name = method_map.fetch(@reflection.options[:dependent], :delete_all)
    delete_method = klass.method(method_name)
 
    records.each do |associate|
      delete_method.call(construct_join_attributes(associate))
    end
  end
end