Sha256: 150a3fb85b474bc9aefef95d6bf3e21a8078fb22a91923f0f7af654fe96e3950

Contents?: true

Size: 967 Bytes

Versions: 30

Compression:

Stored size: 967 Bytes

Contents

module ActiveRecord::Associations::Builder
  class HasAndBelongsToMany < CollectionAssociation #:nodoc:
    def macro
      :has_and_belongs_to_many
    end

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

    def build
      reflection = super
      define_destroy_hook
      reflection
    end

    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

    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
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
activerecord-4.0.13 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.13.rc1 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.11.1 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.12 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.11 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.10 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.10.rc2 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.10.rc1 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.9 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.8 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.7 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.6 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.6.rc3 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.6.rc2 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.6.rc1 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.5 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.4 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.4.rc1 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.3 lib/active_record/associations/builder/has_and_belongs_to_many.rb
activerecord-4.0.2 lib/active_record/associations/builder/has_and_belongs_to_many.rb