has_and_belongs_to_many.rb 576 字节
Newer Older
1 2
module ActiveRecord::Associations::Builder
  class HasAndBelongsToMany < CollectionAssociation #:nodoc:
3 4 5
    def macro
      :has_and_belongs_to_many
    end
6

7
    def valid_options
8
      super + [:join_table, :association_foreign_key]
9
    end
10

11
    def self.define_callbacks(model, reflection)
12
      super
A
Aaron Patterson 已提交
13
      name = reflection.name
J
Jon Leighton 已提交
14 15 16
      model.send(:include, Module.new {
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def destroy_associations
17
            association(:#{name}).delete_all
J
Jon Leighton 已提交
18 19 20 21 22
            super
          end
        RUBY
      })
    end
23 24
  end
end