Class: ActiveRecord::Associations::Builder::HasAndBelongsToMany

Inherits:
CollectionAssociation show all
Defined in:
activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb

Overview

:nodoc:

Constant Summary

Constants inherited from CollectionAssociation

CollectionAssociation::CALLBACKS

Instance Attribute Summary

Attributes inherited from CollectionAssociation

#block_extension, #extension_module

Attributes inherited from Association

#model, #name, #options, #scope

Instance Method Summary collapse

Methods inherited from CollectionAssociation

#define_callback, #define_readers, #define_writers, #extension_module_name, #initialize, #wrap_block_extension, #writable?

Methods inherited from Association

build, #configure_dependency, #define_accessors, #define_readers, #define_writers, #initialize, #mixin, #valid_dependent_options, #validate_options

Constructor Details

This class inherits a constructor from ActiveRecord::Associations::Builder::CollectionAssociation

Instance Method Details

#buildObject


11
12
13
14
15
# File 'activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb', line 11

def build
  reflection = super
  define_destroy_hook
  reflection
end

#define_destroy_hookObject


17
18
19
20
21
22
23
24
25
26
27
# File 'activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb', line 17

def define_destroy_hook
  name = self.name
  model.send(:include, Module.new {
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def destroy_associations
        association(:#{name}).delete_all
        super
      end
    RUBY
  })
end

#macroObject


3
4
5
# File 'activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb', line 3

def macro
  :has_and_belongs_to_many
end

#valid_optionsObject


7
8
9
# File 'activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb', line 7

def valid_options
  super + [:join_table, :association_foreign_key]
end