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

Inherits:
CollectionAssociation show all
Defined in:
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, #reflection, #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 '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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_record/associations/builder/has_and_belongs_to_many.rb', line 27

def define_destroy_hook
  name = self.name
  model.send(:include, Module.new {
    class_eval "def destroy_associations\nassociation(:\#{name}).delete_all\nsuper\nend\n", __FILE__, __LINE__ + 1
  })
end

#macroObject



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

def macro
  :has_and_belongs_to_many
end

#show_deprecation_warningsObject



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

def show_deprecation_warnings
  super

  [:delete_sql, :insert_sql].each do |name|
    if options.include? name
      ActiveSupport::Deprecation.warn("The :#{name} association option is deprecated. Please find an alternative (such as using has_many :through).")
    end
  end
end

#valid_optionsObject



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

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